Skip to content

TextualSelect is not ExecutableReturnsRows and isn't accepted by from_statement #9398

Closed
@zzzeek

Description

@zzzeek
Member

Discussed in #9395

from typing import Optional

from sqlalchemy import create_engine
from sqlalchemy import select
from sqlalchemy import text
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import Session


class Base(DeclarativeBase):
    pass


class User(Base):
    __tablename__ = "user_account"
    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str]
    fullname: Mapped[Optional[str]]


engine = create_engine("sqlite+pysqlite:///:memory:", echo=True)
session = Session(engine)

textual_sql = text("SELECT id, name, fullname FROM user_account ORDER BY id")
textual_sql = textual_sql.columns(User.id, User.name, User.fullname)
orm_sql = select(User).from_statement(textual_sql)
for user_obj in session.execute(orm_sql).scalars():
    print(user_obj)

Activity

added
bugSomething isn't working
typingpep -484 typing issues. independent of "mypy"
near-term releaseaddition to the milestone which indicates this should be in a near-term release
on Mar 1, 2023
added this to the 2.0.x milestone on Mar 1, 2023
sqla-tester

sqla-tester commented on Mar 1, 2023

@sqla-tester
Collaborator

Mike Bayer has proposed a fix for this issue in the main branch:

TextualSelect is ReturnsRowsRole https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4484

added a commit that references this issue on Feb 9, 2024
45f7b3b
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 releasetypingpep -484 typing issues. independent of "mypy"

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zzzeek@sqla-tester

        Issue actions

          TextualSelect is not ExecutableReturnsRows and isn't accepted by from_statement · Issue #9398 · sqlalchemy/sqlalchemy