fix: resolve relationship refs to explicit override DTOs#176
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds RegistryTypeInfo.resolves_scoped_references and a helper to detect existing forward-ref targets, then updates StrawberryRegistry._register to conditionally register namespace default_name and selectively refresh forward and scoped type references. Adds a unit test asserting explicit related-type registration wins over auto-generated defaults. ChangesScoped Reference Resolution
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Follow-up pushed for the review comment and diff scope.
Validation rerun:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/strawchemy/utils/registry.py`:
- Around line 125-135: The boolean in resolves_scoped_references is doing two
distinct checks (explicit global scope vs. implicit override/default-name
takeover); extract the second branch into a clearly named helper property (e.g.,
_is_override_with_default_name) or at minimum add an inline comment explaining
the two branches, then have resolves_scoped_references return the combined
result using that helper and keep the original semantics (referencing
self.model, self.exclude_from_scope, self.scope, self.override,
self.user_defined, and self.default_name to preserve behavior).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 04392e2c-1aa6-474d-b26d-333d9d44a830
⛔ Files ignored due to path filters (2)
tests/unit/mapping/__snapshots__/test_schemas/test_query_schemas[override_with_custom_name].gqlis excluded by!**/__snapshots__/**tests/unit/mapping/__snapshots__/test_schemas/test_query_schemas[scope_schema_in_the_middle].gqlis excluded by!**/__snapshots__/**
📒 Files selected for processing (2)
src/strawchemy/utils/registry.pytests/unit/mapping/test_schemas.py
Summary
Fixes relationship field references that stay pointed at an earlier generated/default DTO when a user-defined
override=TrueDTO for the related model is registered later.This can happen when one model type is decorated before the explicit related model type has been imported. The relationship field records a reference to the generated DTO, and the later explicit override previously did not satisfy that pending reference.
Change
RegistryTypeInfo.resolves_scoped_referencesso a user-definedoverride=TrueDTO with the model default name can update pending references for the generated/default DTO of the same model.scope="schema"and internalglobalhandling.FruitNode.colorresolves to the later explicitColorNodeinstead of a generatedColorType.Validation
uv run pytest tests/unit -q --snapshot-warn-unused-> 205 passed, 2 skippeduv run ruff check src/strawchemy/utils/registry.py tests/unit/mapping/test_schemas.pyuv run ruff format --check src/strawchemy/utils/registry.py tests/unit/mapping/test_schemas.pyRelated to #175.
Summary by CodeRabbit