Skip to content

fix: Allow overriding column definitions in schema inheritance#302

Open
Andreas Albert (AndreasAlbertQC) wants to merge 2 commits intomainfrom
fix/allow-column-override-in-inheritance
Open

fix: Allow overriding column definitions in schema inheritance#302
Andreas Albert (AndreasAlbertQC) wants to merge 2 commits intomainfrom
fix/allow-column-override-in-inheritance

Conversation

@AndreasAlbertQC
Copy link
Collaborator

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:

class FirstSchema(dy.Schema):
    x = dy.Int64()

class SecondSchema(FirstSchema):
    x = dy.Int64(nullable=True)  # Override — should be allowed

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 b with an alias that clashes with an inherited column a).

Validation

  • test_override — new test that verifies subclass column overrides work
  • test_duplicate_alias_same_schema and test_duplicate_alias_inherited_schema — existing tests still pass, confirming alias conflict detection is preserved

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]>
@github-actions github-actions bot added the fix label Mar 24, 2026
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (72fb1a6) to head (13f7403).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Column with 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants