summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorramonvg <ramonvillalongaa@gmail.com>2020-06-24 09:51:56 -0400
committerGord Thompson <gord@gordthompson.com>2020-06-24 12:53:59 -0600
commit0fd256d9937222ddf9f9d138641a59247ce0d450 (patch)
treea44996e422586c49695395ce31522a2035a8a333
parent660a340bff8fcefd2826032e75210c0924a2335e (diff)
downloadsqlalchemy-0fd256d9937222ddf9f9d138641a59247ce0d450.tar.gz
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 <sqlalchemy.sql.elements.BinaryExpression object at 0x7f3d90426370>. ``` I'm just adding a test that ensures the behavior. Fixes: [4556](https://github.com/sqlalchemy/sqlalchemy/issues/4556) ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> 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: #<issue number>` 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: #<issue number>` 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
-rw-r--r--test/orm/test_update_delete.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/orm/test_update_delete.py b/test/orm/test_update_delete.py
index 310b17047..b0d718315 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