-
Notifications
You must be signed in to change notification settings - Fork 10
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
ORM 2.0 style fake session mutations #341
Comments
Already realised a slight issue. The:
Actually needs to be
This is because each select object is a different object and we need to be able to actually compare them and have them match in this statement. |
And FYI, after changing this in a local branch, the following quick test (copied and modified from test_update_calls()) passes with sqlalchemy >= 1.4.0
And I do have a branch with this change in as it currently stands: https://github.com/jonyscathe/mock-alchemy/tree/jonyscathe/execute_mutate But figured I would for a comment or two before writing any tests and making a PR |
Actually... I might work on this a bit more. Ideally, things like
Would also work for adding data. Edit:
Treating execute as both a mutate and unify keyword - ideally will be able to work out when it should/shouldn't unify - for example with the two statements at the top of this post, the first should not unify, the second should - the key difference being the Code isn't still WIP, not linted, tested, etc. Still working on update/delete and then when to/not unify. |
Is your feature request related to a problem? Please describe.
Cannot currently read mock data back using
session.execute(select(my_table)).all()
Describe the solution you'd like
Currently the following works:
I would like the following to also work:
Describe alternatives you've considered
Can stick with ORM 1.0 style queries in tests if this becomes too difficult.
Additional context
I have tested the following change locally and it does work (for at least very simple cases).
Changing in mocking.py:
to:
plus adding
from sqlalchemy import select
up the top.After that, when I have done a simple add I can read back my data using either
session.execute(select(my_table)).all()
or ``session.query(my_table).all()` and that all works fine.If it was that simple I would have a PR up already.
However, that code would likely break things for some people.
Firstly, I don't believe using select() in that way is not allowable in older versions of sqlalchemy (such as 1.3.22). In the current mock-alchemy tests, the 1.3.22 tests fail with a
TypeError: 'DeclarativeMeta' object is not iterable
.Secondly, if the 'my_table' object is being mocked and isn't a Column expression, FROM clause or other columns clause element then the
select(type(to_add))
will throw ansqlalchemy.exc.ArgumentError
.Both of these issues could be resolved with a simple try/except block:
But before doing something like that I wanted to get your opinion on that style of programming as some people are not huge fans of those sort of try/except blocks.
The text was updated successfully, but these errors were encountered: