summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2019-04-11 01:00:19 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2019-04-11 01:00:19 +0000
commit53c65ed93ade1fc99c75e1f0bf055cd129596c06 (patch)
tree785fe2ff81daa1064b529ff4694eb5ac70330b44
parentdeed49489b99227b292f801e227b987b26a22b71 (diff)
parent36949938e83f1e3096d24b74d33f19512d014520 (diff)
downloadsqlalchemy-53c65ed93ade1fc99c75e1f0bf055cd129596c06.tar.gz
Merge "Don't use and_() inside of Query.filter_by"
-rw-r--r--doc/build/changelog/unreleased_13/4606.rst12
-rw-r--r--lib/sqlalchemy/orm/query.py2
-rw-r--r--test/orm/test_query.py9
3 files changed, 22 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_13/4606.rst b/doc/build/changelog/unreleased_13/4606.rst
new file mode 100644
index 000000000..6bdfa8a5f
--- /dev/null
+++ b/doc/build/changelog/unreleased_13/4606.rst
@@ -0,0 +1,12 @@
+.. change::
+ :tags: bug, orm
+ :tickets: 4606
+
+ Adjusted the :meth:`.Query.filter_by` method to not call :func:`.and()`
+ internally against multiple criteria, instead passing it off to
+ :meth:`.Query.filter` as a series of criteria, instead of a single criteria.
+ This allows :meth:`.Query.filter_by` to defer to :meth:`.Query.filter`'s
+ treatment of variable numbers of clauses, including the case where the list
+ is empty. In this case, the :class:`.Query` object will not have a
+ ``.whereclause``, which allows subsequent "no whereclause" methods like
+ :meth:`.Query.select_from` to behave consistently.
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 9544b7d11..5d340654c 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -1791,7 +1791,7 @@ class Query(object):
_entity_descriptor(self._joinpoint_zero(), key) == value
for key, value in kwargs.items()
]
- return self.filter(sql.and_(*clauses))
+ return self.filter(*clauses)
@_generative(_no_statement_condition, _no_limit_offset)
def order_by(self, *criterion):
diff --git a/test/orm/test_query.py b/test/orm/test_query.py
index 8f962d581..b31647a72 100644
--- a/test/orm/test_query.py
+++ b/test/orm/test_query.py
@@ -2880,6 +2880,15 @@ class FilterTest(QueryTest, AssertsCompiledSQL):
checkparams={"email_address_1": "ed@ed.com", "name_1": "ed"},
)
+ def test_empty_filters(self):
+ User = self.classes.User
+ sess = create_session()
+
+ q1 = sess.query(User)
+
+ is_(None, q1.filter().whereclause)
+ is_(None, q1.filter_by().whereclause)
+
def test_filter_by_no_property(self):
addresses = self.tables.addresses
sess = create_session()