Closed
Description
Discussed in #9804
from sqlalchemy import literal
from sqlalchemy import select
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
class Base(DeclarativeBase):
pass
class Foo(Base):
__tablename__ = "test"
id: Mapped[int] = mapped_column(primary_key=True)
val: Mapped[int]
inner = select(Foo.id).where(Foo.id.is_not(literal(None)))
assert inner._propagate_attrs
sq1 = inner.scalar_subquery()
assert sq1._propagate_attrs
stmt = select(sq1).where(Foo.val == 3)
assert stmt._propagate_attrs
need to determine if setting ORM for this is OK, since it doesnt actually return ORM objects, but we want autoflush to take place
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
sqla-tester commentedon May 19, 2023
Mike Bayer has proposed a fix for this issue in the main branch:
use an ORM compile state for all statements with any ORM entities anywhere https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4622
zzzeek commentedon May 19, 2023
this was extended to accommodate for all WHERE / GROUP BY/ HAVING , DML WHERE , and compound select, which required adding a new union-level ORM compile state. This might be too much just to get autoflush, but that's the current architecture and documentation - the alternative would be to invoke autoflush for non-ORM statements separately.
'NoneType' object has no attribute 'mapper'
AttributeError #10098use an ORM compile state for all statements with any ORM entities any…