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

Sequential queries not working #161

Closed
jonyscathe opened this issue Oct 13, 2021 · 2 comments · Fixed by #162
Closed

Sequential queries not working #161

jonyscathe opened this issue Oct 13, 2021 · 2 comments · Fixed by #162
Assignees
Labels
bug Something isn't working

Comments

@jonyscathe
Copy link
Contributor

Describe the bug
If there is some query not terminated with one of the supported boundary functions, it appears the next query doesn't wort as expected

To Reproduce

mock_session = UnifiedAlchemyMagicMock(
    data=[([mock.call.query(db.TestTable), mock.call.filter(db.TestTable.id == 4)], [db.TestTable(id=4, col1=2)])]
),

mock_session.query(db.SecondTestTable).filter(db.SecondTestTable.id == 5).update({'col2': 6})

rows_deleted_1 = mock_session.query(db.TestTable).filter(db.TestTable.id == 4).delete()

rows_deleted_2 = mock_session.query(db.TestTable).filter(db.TestTable.id == 4).delete()

At this point rows_deleted_1 will be 0 and rows_deleted_1 will be 1

Expected behavior
The first delete should delete the row, not the second one.
Also, if the deletes above were replaced with .all() then the first .all() would return [] and the second would correctly return [db.TestTable(id=4, col1=2)].

Additional context
Looks to me like the mock_session's query gets mucked up by the update() call.
Obviously update() isn't testable with mock-alchemy so all I can do is check that update() is called with the correct arguments.
But not being able to test the sql query directly after an update leads to some gaps in my test coverage which aren't ideal. If it is something easily fixable I would appreciate this being looked at, but if not I'll just have to test that the delete is being called with the right arguments rather than checking that things get deleted.

@jonyscathe jonyscathe added the bug Something isn't working label Oct 13, 2021
@rajivsarvepalli rajivsarvepalli self-assigned this Oct 18, 2021
@rajivsarvepalli
Copy link
Owner

rajivsarvepalli commented Oct 23, 2021

Agreed this is incorrect behavior. Ideally, any unknown call should not mess up the mock session. This is due to the way filter, query, etc. are handled, I will have to investigate more to find a better solution.

As a temporary solution, I can simply add update as an operation and make it not do anything. It seems if you call filter, query, etc. without a "terminating operation", this causes some strange issues. Let me if there other operators you would like as part of this list.

@jonyscathe
Copy link
Contributor Author

jonyscathe commented Oct 25, 2021

Awesome, sounds like a good way to solve this issue. There aren't any other operators that I am having issues with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants