Repository navigation
Conversation
_produce_column_copies(), used when a Column or MappedColumn is inherited from a mixin/non-declarative base and copied onto the mapped class, called _collect_annotation() with expect_mapped hardcoded to True at both of its call sites. This bypassed self.allow_unmapped_annotations entirely, so a bare (non-Mapped[]) annotation paired with such a column raised MappedAnnotationError even when __allow_unmapped__ = True was set - despite the error's own text claiming that flag should suppress it. By contrast, the equivalent path for attributes declared directly on the mapped class passes expect_mapped=None, correctly deferring to the flag via the dynamic computation in _collect_annotation. Pass "not self.allow_unmapped_annotations" instead of a hardcoded True at both call sites, so the strict default is preserved but the flag is now honored, matching the direct-attribute path.
|
Hi, and thanks for the pull request! This project accepts pull requests only for issues that a maintainer has already marked with the open for pull requests label. That way we can settle on an approach before anyone spends time writing code. This pull request references issue #9369, which hasn't been marked open for pull requests, so the change isn't authorized yet and I'm closing it automatically. Once a maintainer adds the label to #9369, reopen this pull request and it will stay open. If #9369 needs more detail before that can happen, a complete runnable example is usually the missing piece, and adding one to the issue is the fastest way to get there. This is automatic and procedural. It isn't a judgment on your change, and nothing you've written here is lost. Thanks for your interest in the project! |
|
Traced this through both functions to be sure, and the two-line fix is semantically exact:
The regression test targets the right path (mixin + explicit Nothing else to flag — clean fix for a long-standing gap. |
| name, | ||
| annotation, | ||
| originating_class, | ||
| not self.allow_unmapped_annotations, |
There was a problem hiding this comment.
I think this and below could instead pass None.
@zzzeek thoughts?
There was a problem hiding this comment.
in other places for such a case we pass none not False
There was a problem hiding this comment.
he's correct. use None please, instead of True
also we need to document what "allow_unmapped" means, determine if False means anything and if not we need to change this parameter
There was a problem hiding this comment.
what im getting at is this is a bigger change that warrants a lot of care and caution. it's not a one liner. especially in the tests. needs a lot more and they need to be integrated with what we have already.
There was a problem hiding this comment.
@zzzeek Should I check it at broader level and then let you know ?
| def test_allow_unmapped_column_on_mixin(self, decl_base): | ||
| """test #9369""" | ||
|
|
||
| class Mixin: |
There was a problem hiding this comment.
this is not what the test case in the issue says....the test case has the __allow_unmapped__ on the Mixin.
in fact we should test it in all combinations: on just the mixin, on just the concrete class, on both. use testing.variations
|
|
||
| class MyClass(Mixin, decl_base): | ||
| __tablename__ = "mytable" | ||
| __allow_unmapped__ = True |
There was a problem hiding this comment.
this file will also need to be copied using tools/sync_test_files.py
Fixes #9369
_produce_column_copies(), used when aColumnorMappedColumnis inherited from a mixin/non-declarative base and copied onto the class being mapped, calls_collect_annotation()withexpect_mappedhardcoded toTrueat both of its call sites. This bypassesself.allow_unmapped_annotationsentirely, so a bare (non-Mapped[]) type-annotated attribute paired with such a column — inherited from a mixin — raisesMappedAnnotationErroreven when__allow_unmapped__ = Trueis set on the mapped class or a superclass, despite the error's own text claiming that flag should suppress it:By contrast, the equivalent path for attributes declared directly on the mapped class passes
expect_mapped=None, which correctly defers to the flag via the dynamic computation already present in_collect_annotation.Changes
not self.allow_unmapped_annotationsinstead of a hardcodedTrueat both_produce_column_copies()call sites, preserving the strict default while honoring the flag, matching the direct-attribute path's behavior.test_allow_unmapped_column_on_mixin) alongside the existingtest_allow_unmapped_on_mixin/test_allow_unmapped_colstests.Test plan
main, confirmed fixed__allow_unmapped__) still correctly raisesMappedAnnotationErrorfor the same mixin shape — no over-broadeningmainand passes with the fixpytest test/orm/declarative/— 2852 passedpytest test/orm/(full ORM suite) — 10937 passedflake8/black --checkclean on both changed files