Create SIGRef objects when converting dict to Spot object in the spot object's own __post_init__ method rather than in add_spot.py

This commit is contained in:
Ian Renton
2026-07-10 17:45:43 +01:00
parent 600a330e63
commit eee0d70140
10 changed files with 26 additions and 25 deletions
+11
View File
@@ -133,6 +133,17 @@ class Spot:
# The ID the source gave it, if any.
source_id: str | None = None
def __post_init__(self):
"""Normalise fields that don't survive a plain dict to Spot conversion. This is used in the "add spot" API
endpoint where the client is submitting JSON, and we want to recreate a full Spot object, including nested
objects such as the sig_refs list.."""
if self.sig_refs:
self.sig_refs = [
sig_ref if isinstance(sig_ref, SIGRef) else SIGRef(**sig_ref)
for sig_ref in self.sig_refs
]
def infer_missing(self, credentials=None):
"""Infer missing parameters where possible"""