-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"implicit combining column" warning not emitting for two columns from two different aliases against same parent table #10960
Comments
hi
Map the columns with distinct names then create the composites against those names: class Foo(Base):
__table__ = (
foo_table.outerjoin(
bar_alias_1, foo_table.c.bar_1_id == bar_alias_1.id
)
.outerjoin(bar_alias_2, foo_table.c.bar_2_id == bar_alias_2.id)
.outerjoin(bar_alias_3, foo_table.c.bar_3_id == bar_alias_3.id)
)
id: orm.Mapped[int] = orm.column_property(foo_table.c.id)
_bar_1_id: orm.Mapped[int] = orm.column_property(
foo_table.c.bar_1_id, bar_alias_1.id
)
_bar_2_id: orm.Mapped[int] = orm.column_property(
foo_table.c.bar_2_id, bar_alias_2.id
)
_bar_3_id: orm.Mapped[int] = orm.column_property(
foo_table.c.bar_3_id, bar_alias_3.id
)
b1v1 = orm.column_property(bar_alias_1.value_1)
b1v2 = orm.column_property(bar_alias_1.value_2)
b2v1 = orm.column_property(bar_alias_2.value_1)
b2v2 = orm.column_property(bar_alias_2.value_2)
b3v1 = orm.column_property(bar_alias_3.value_1)
b3v2 = orm.column_property(bar_alias_3.value_2)
bar_1: orm.Mapped[CompositeBar] = orm.composite(
CompositeBar, "b1v1", "b1v2" #bar_alias_1.value_1, bar_alias_1.value_2
)
bar_2: orm.Mapped[CompositeBar] = orm.composite(
CompositeBar, "b2v1", "b2v2", #bar_alias_2.value_1, bar_alias_2.value_2
)
bar_3: orm.Mapped[CompositeBar] = orm.composite(
CompositeBar, "b3v1", "b3v2", #bar_alias_3.value_1, bar_alias_3.value_2
) I don't have a fix for this in 2.0 as it would require me to entirely rearchitect how Composite gets these values. |
Hmm OK actually I think my approach above is how this should be mapped. what's failing is that the warning that tells you it's implicitly combining two columns is not happening for this very specific situation, which is the warning that would let you know you need to map these columns individually. |
Superthanks for the clarification! I was looking into the root cause and I just gave up as it would require somewhat thorough overhaul to get this right. Looking forward to the fix. |
Describe the bug
Description
The following code yields a strange result. I'm expecting
bar_1
,bar_2
, andbar_3
to be mapped asCompositeBar(value_1="a", value_2="b")
,CompositeBar(value_1="c", value_2="d")
, andCompositeBar(value_1="e", value_2="f")
respectively, but actually it ended up with everyCompositeBar
beingCompositeBar(value_1="e", value_2="f")
as if it got mapped tobar_alias_3
and the rest were ignored.BTW the reason why I didn't use relationships here is that the actual code I'm working on has more complex mappings like the composite instance gets mapped to both the table that corresponds to the containing class, and the table that it refers to.
Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
No response
SQLAlchemy Version in Use
2.0.25
DBAPI (i.e. the database driver)
sqlite3 module
Database Vendor and Major Version
SQLite 2.6.0
Python Version
3.8.16
Operating system
macOS
To Reproduce
Error
Actual result:
Expected:
Additional context
No response
The text was updated successfully, but these errors were encountered: