Skip to content
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

Support for unified Core+ORM SQLAlchemy query style #134

Open
cblegare opened this issue Aug 12, 2021 · 1 comment
Open

Support for unified Core+ORM SQLAlchemy query style #134

cblegare opened this issue Aug 12, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@cblegare
Copy link

Is your feature request related to a problem? Please describe.

With SQLAlchemy 1.4, but Core-style and ORM-style queries can be run the same way:

class MyModel(Base):
    __tablename__ = "model"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, nullable=False)

statement = select(MyModel)

result = session.execute(statement)
all_rows = result.all;()

Details in SQLAlchemy documentation

Describe the solution you'd like

statement = select(MyModel)

session = UnifiedAlchemyMagicMock(
    data=[
        (
            [
                mock.call.execute(statement),
            ],
            [
                MyModel(id=1234, name="foo"),
            ]
        )
    ]
)

result = session.execute(stmt)
found = result.one_or_none()

assert found.name == "foo"

Describe alternatives you've considered

In the meantime, I'll be using a normal mock with return values.

@jonyscathe
Copy link
Contributor

Is there any chance of this (or something like it) happening?
With the session.execute(statement) being the preferred ORM method going forward with SQLAlchemy 2.0 and session.query() being marked as legacy it would be nice to convert queries over during SQLAlchemy 2.0 migration, however I am guessing that I won't be able to do this and continue using mock-alchemy unless this issue is addressed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants