Repository navigation
Fix validate_no_field_redeclaration blaming the wrong ancestor - #2906
Conversation
|
Review note (not acted on, recording for future reference): this fix moves `validate_no_field_redeclaration`'s ancestor-chain resolution onto the direct-column path (`resolve_field_owners` → `get_extends_parent_map`), matching what #2866 already did for `validate_no_relationship_redeclaration`. `validate_extends_target`'s cycle check (same file, unchanged, called in the same request) still uses the JSON-hydrated path (`load_parent_map`/`declared_parent`). Under a malformed `properties` JSON column on an extends-declaration row, `parse_declaration_row` could silently drop that edge from the JSON-hydrated path while the direct-column path still sees it — meaning the cycle check and the redeclaration check could theoretically disagree about the extends graph. This divergence between the two resolution mechanisms was introduced by #2866 (not by this PR); this PR just extends the same accepted pattern from relationships to fields. Low-probability edge case requiring data corruption to manifest, not a live bug — flagging for a possible future follow-up (e.g. unifying both call sites on one parent-map resolver) rather than fixing here, to keep this PR scoped to the blame-message bug in #2871. |
validate_no_field_redeclaration resolved the effective field set via resolve_effective_fields, which discards per-field ownership, and always named the immediate extends parent as the "already declared by" schema in its collision error — even when the true declaring schema was a grandparent or further ancestor. Switch to NodeService::resolve_field_owners's owner map, mirroring the fix already applied to validate_no_relationship_redeclaration in #2866. Adds a blame assertion to the two existing grandparent-collision tests (create_schema-with-extends and add_fields-only) confirming the error names the true declaring schema, not the immediate parent it's merely inherited through. Closes #2871. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…failure validate_no_field_redeclaration's internal-error wrapper named parent_id as though it were the schema whose lookup failed, even though the DB failure inside resolve_field_owners can occur on any ancestor further up the chain. The true failing schema id was still present (nested inside the underlying NodeServiceError), just prefixed by a wrapper phrase that read as if parent_id was the one that failed. Reword the wrapper to describe the chain walk starting from parent_id, not the failing schema. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…nds re-target call site The re-target call site's existing collision test only collided with the immediate new parent, where declaring_schema == new_parent regardless of whether the blame fix is present — it couldn't distinguish correct blame from buggy blame at that specific call site. Add a grandparent-collision test mirroring the ones already covering the create-schema and add-fields-only call sites, confirming the error names the schema that actually declares the field, not the immediate new parent. Co-Authored-By: Claude Sonnet 5 <[email protected]>
63ca981 to
47d63ba
Compare
|
Follow-up from a final confirmatory review pass (completed after merge, run in parallel with the merge decision — see below): no confirmed correctness bugs found. Two minor, non-blocking findings worth recording:
Recording both since the review that surfaced them landed after merge (severe shared-machine load meant this pass took ~8.5 minutes to return); neither warrants reopening or a hasty follow-up PR, but both are fair candidates for a future consistency-cleanup pass on the extends-chain resolvers. |
Summary
validate_no_field_redeclaration(packages/core/src/schema/mod.rs) resolved the effective field set viaresolve_effective_fields, which discards per-field ownership, and always named the immediateparent_idas the "already declared by" schema — even when the true declaring schema was a grandparent or further ancestor.NodeService::resolve_field_owners's owner map (its second tuple element) to name the schema that actually declares the colliding field, mirroring the fix already applied tovalidate_no_relationship_redeclarationin Enforce ADR-078 field/relationship shadowing on more write paths #2866.Closes #2871.
Test plan
test_redeclaring_a_field_inherited_from_a_grandparent_rejected(create_schema-with-extends path) confirming the error names the true declaring ancestor ("root"), not the immediate parent ("mid")test_add_fields_only_call_rejects_a_field_inherited_from_a_grandparent(add_fields-only update path)cargo test -p nodespace-core --lib schema::— 170 passedcargo clippy -p nodespace-core --lib -- -D warnings— cleancargo fmt -p nodespace-core -- --check— cleanbun run test:all+cargo build --bin nodespaced+ e2e suite) — passed🤖 Generated with Claude Code