fix: Allow overriding column definitions in schema inheritance#302
Open
Andreas Albert (AndreasAlbertQC) wants to merge 2 commits intomainfrom
Open
fix: Allow overriding column definitions in schema inheritance#302Andreas Albert (AndreasAlbertQC) wants to merge 2 commits intomainfrom
Andreas Albert (AndreasAlbertQC) wants to merge 2 commits intomainfrom
Conversation
The duplicate alias check from #291 also rejected intentional column overrides in subclasses. Before merging the child namespace, walk the parent MRO to remove columns that share the same attribute name so the child definition takes precedence, while still detecting genuine alias conflicts. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #302 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 56 56
Lines 3218 3230 +12
=========================================
+ Hits 3218 3230 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Copilot started reviewing on behalf of
Andreas Albert (AndreasAlbertQC)
March 24, 2026 16:41
View session
There was a problem hiding this comment.
Pull request overview
Fixes a regression from PR #291 where duplicate-alias detection prevented legitimate subclass overrides of inherited schema columns, by adjusting schema metadata merging so child column definitions take precedence.
Changes:
- Remove inherited column entries when a subclass defines a
Columnwith the same attribute name (override semantics). - Add a regression test ensuring schema subclass overrides don’t raise during class creation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dataframely/_base_schema.py |
Updates SchemaMeta.__new__ to drop overridden inherited columns before merging child metadata, preserving duplicate-alias conflict detection. |
tests/schema/test_base.py |
Adds a regression test for overriding a column definition in a schema subclass. |
- Scan all bases/MROs instead of breaking after the first match, so multiple-inheritance overrides remove all inherited columns - Add assertions to test_override to verify the child definition actually takes precedence Co-Authored-By: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PR #291 introduced duplicate alias detection, but it also broke overriding column definitions in subclasses. For example, this valid pattern started raising an error:
Changes
Before merging the child namespace into the inherited metadata, walk the parent MRO to identify columns that share the same attribute name as a child-defined column. Remove those parent columns so the child's definition takes precedence, while still detecting genuine alias conflicts (e.g., a new column
bwith an alias that clashes with an inherited columna).Validation
test_override— new test that verifies subclass column overrides worktest_duplicate_alias_same_schemaandtest_duplicate_alias_inherited_schema— existing tests still pass, confirming alias conflict detection is preserved