diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2020-05-23 21:11:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-05-23 21:11:50 +0000 |
commit | 56f302138622b868a9f6fc63d4f080e5c237dd3e (patch) | |
tree | 294dda86754234fcf9765a09157560fd382e88cc /lib | |
parent | 330381a3312394d9663d157182cf97cea8b43fcc (diff) | |
parent | 8c10e29dc7aa2356d0f3f5110b2c9dade9d87096 (diff) | |
download | sqlalchemy-56f302138622b868a9f6fc63d4f080e5c237dd3e.tar.gz |
Merge "Improve error message when using :meth:`_query.Query.filter_by` in a query where the first entity is not a mapped class."
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 02cfbfcb2..7e65f26e2 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1784,8 +1784,17 @@ class Query(Generative): """ + zero = self._joinpoint_zero() + if zero is None: + raise sa_exc.InvalidRequestError( + "Can't use filter_by when the first entity '%s' of a query " + "is not a mapped class. Please use the filter method instead, " + "or change the order of the entities in the query" + % self._query_entity_zero() + ) + clauses = [ - _entity_descriptor(self._joinpoint_zero(), key) == value + _entity_descriptor(zero, key) == value for key, value in kwargs.items() ] return self.filter(*clauses) |