Skip to content

Commit 294fcb7

Browse files
jirhikerCopilot
andauthored
Update schemas/thing.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b075aa5 commit 294fcb7

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

schemas/thing.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,28 @@ def use_dummy_values(cls, v):
143143
return v
144144

145145
for alternate_id in v:
146-
alternate_id["thing_id"] = -1 # dummy value
147-
return v
148-
146+
normalized: list = []
147+
for alternate_id in v:
148+
# If we already have a Pydantic model instance, set the attribute if possible.
149+
if isinstance(alternate_id, BaseModel):
150+
if hasattr(alternate_id, "thing_id"):
151+
setattr(alternate_id, "thing_id", -1)
152+
normalized.append(alternate_id)
153+
else:
154+
data = alternate_id.model_dump()
155+
data["thing_id"] = -1
156+
normalized.append(data)
157+
# If it's a plain dict, add the dummy thing_id key.
158+
elif isinstance(alternate_id, dict):
159+
data = dict(alternate_id)
160+
data["thing_id"] = -1
161+
normalized.append(data)
162+
else:
163+
# For any unexpected type, leave as-is and let normal validation
164+
# handle potential errors.
165+
normalized.append(alternate_id)
149166

150-
class CreateWell(CreateBaseThing, ValidateWell):
167+
return normalized
151168
"""
152169
Schema for creating a well.
153170
"""

0 commit comments

Comments
 (0)