From: ramonvg Date: Wed, 24 Jun 2020 13:51:56 +0000 (-0400) Subject: Fixes: #4556 - Test that prevents passing a filter to Session.query when running... X-Git-Tag: rel_1_4_0b1~251^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fd256d9937222ddf9f9d138641a59247ce0d450;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixes: #4556 - Test that prevents passing a filter to Session.query when running an update ### Description There was a bug in 1.3.8 that allowed passing a `BinaryExpression` to `Session().query`. I assume it was fixed in https://github.com/sqlalchemy/sqlalchemy/commit/3ab2364e78641c4f0e4b6456afc2cbed39b0d0e6 since now it raises: ``` sqlalchemy.exc.ArgumentError: subject table for an INSERT, UPDATE or DELETE expected, got . ``` I'm just adding a test that ensures the behavior. Fixes: [4556](https://github.com/sqlalchemy/sqlalchemy/issues/4556) ### Checklist This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #5419 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5419 Pull-request-sha: af7601dff1a0dce94802627a9fe2398be60d8186 Change-Id: Ic1a9075e7e8520510964fdd3d7ac14fba550110c --- diff --git a/test/orm/test_update_delete.py b/test/orm/test_update_delete.py index 310b170479..b0d7183154 100644 --- a/test/orm/test_update_delete.py +++ b/test/orm/test_update_delete.py @@ -607,6 +607,19 @@ class UpdateDeleteTest(fixtures.MappedTest): in_(jill, sess) not_in_(jane, sess) + def test_update_with_filter_statement(self): + """test for [ticket:4556] """ + + User = self.classes.User + + sess = Session() + assert_raises( + exc.ArgumentError, + lambda: sess.query(User.name == "filter").update( + {"name": "update"} + ), + ) + def test_update_without_load(self): User = self.classes.User