]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes: #4556 - Test that prevents passing a filter to Session.query when running...
authorramonvg <ramonvillalongaa@gmail.com>
Wed, 24 Jun 2020 13:51:56 +0000 (09:51 -0400)
committerGord Thompson <gord@gordthompson.com>
Wed, 24 Jun 2020 18:53:59 +0000 (12:53 -0600)
### 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

test/orm/test_update_delete.py

index 310b170479483a23a1a8c923eec1a878ec1b9029..b0d7183154bdf6b7b80c2957be6e806f2cc1457a 100644 (file)
@@ -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