Skip to content

propagate_attrs not set up for scalar subqueries #9805

Closed
@zzzeek

Description

@zzzeek
Member

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

Activity

added
bugSomething isn't working
near-term releaseaddition to the milestone which indicates this should be in a near-term release
on May 19, 2023
added this to the 2.0.x milestone on May 19, 2023
sqla-tester

sqla-tester commented on May 19, 2023

@sqla-tester
Collaborator

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

zzzeek commented on May 19, 2023

@zzzeek
MemberAuthor

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.

added a commit that references this issue on Feb 9, 2024
a2e27eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnear-term releaseaddition to the milestone which indicates this should be in a near-term releaseorm

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zzzeek@sqla-tester

        Issue actions

          propagate_attrs not set up for scalar subqueries · Issue #9805 · sqlalchemy/sqlalchemy