Skip to content

Commit a1bac06

Browse files
robtaylorclaude
andcommitted
Fix Pydantic model forward references and improve error messages
Fix issue where real-world pins.lock files were incorrectly reported as malformed due to unresolved forward references in Pydantic models. Changes: - Call model_rebuild() on Package and LockFile after importing all package types to resolve forward references - Chain validation errors using 'from e' to preserve detailed error information for debugging while showing user-friendly message The model_rebuild() calls are necessary because the lockfile models use forward references to package types (GAPackageDef, QuadPackageDef, etc.) that are only imported later in the __init__.py file. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3132f0d commit a1bac06

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

chipflow/packaging/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
PinCommand,
8282
)
8383

84+
# Rebuild Pydantic models now that all package types are imported
85+
# This resolves forward references in the lockfile models
86+
Package.model_rebuild()
87+
LockFile.model_rebuild()
88+
8489
# NOTE: This module is currently internal to the chipflow CLI.
8590
# The public API will be designed in a future PR after working through
8691
# real-world custom package examples.

chipflow/packaging/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def load_pinlock() -> LockFile:
3636
try:
3737
json = lockfile.read_text()
3838
return LockFile.model_validate_json(json)
39-
except (pydantic.ValidationError, pydantic.PydanticUserError):
39+
except (pydantic.ValidationError, pydantic.PydanticUserError) as e:
4040
raise ChipFlowError(
4141
"Lockfile `pins.lock` is misformed. "
4242
"Please remove and rerun `chipflow pin lock`"
43-
)
43+
) from e
4444

4545
raise ChipFlowError("Lockfile `pins.lock` not found. Run `chipflow pin lock`")
4646

0 commit comments

Comments
 (0)