Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions python/lsst/ci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ def save(self, build_dir: str) -> None:
# Write to build_dir
try:
with open(path, "w", encoding="utf-8") as f:
f.write(self.model_dump_json(indent=2))
if hasattr(self, "model_dump_json"):
f.write(self.model_dump_json(indent=2))
else: # fallback for pydantic v1
f.write(self.json(indent=2))
except OSError as os_err:
print(f"Failed to write to {path}: {os_err}", file=sys.stderr)

Expand All @@ -384,6 +387,7 @@ def from_build_dir(cls, build_dir: str) -> AllProductPRCollections:
The Pydantic model. If `pr_info.json` does not exist or fails
to parse or validate, returns an empty model
(`AllProductPRCollections(items=[])`).

Warns
-----
Prints to `sys.stderr` on read, decode, or validation failures.
Expand All @@ -401,7 +405,11 @@ def from_build_dir(cls, build_dir: str) -> AllProductPRCollections:
return cls(items=[])

try:
return cls.model_validate_json(data)
if hasattr(cls, "model_validate_json"):
return cls.model_validate_json(data)
else: # fallback for pydantic v1
return cls.parse_raw(data)

except json.JSONDecodeError as decode_err:
print(f"Invalid JSON in {path}: {decode_err}", file=sys.stderr)
except pydantic.ValidationError as val_err:
Expand Down
Loading