diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-01 08:41:09 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-01 11:54:21 -0400 |
commit | 5cde12d816b8b32719cee377677667150df07c48 (patch) | |
tree | 2bfe72c72617f617d80301d08e19a845211fad9f /lib/sqlalchemy/sql/elements.py | |
parent | a47c158a9a3b1104698fc0bff47ca58d67cb9191 (diff) | |
download | sqlalchemy-5cde12d816b8b32719cee377677667150df07c48.tar.gz |
Support filter_by() from columns, functions, Core SQL
Fixed regression where :meth:`_orm.Query.filter_by` would not work if the
lead entity were a SQL function or other expression derived from the
primary entity in question, rather than a simple entity or column of that
entity. Additionally, improved the behavior of
:meth:`_sql.Select.filter_by` overall to work with column expressions even
in a non-ORM context.
Fixes: #6414
Change-Id: I316b5bf98293bec1ede08787f6181dd14be85419
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index e27b97802..416a4e82e 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -300,6 +300,13 @@ class ClauseElement( f = f._is_clone_of return s + @property + def entity_namespace(self): + raise AttributeError( + "This SQL expression has no entity namespace " + "with which to filter from." + ) + def __getstate__(self): d = self.__dict__.copy() d.pop("_is_clone_of", None) @@ -4664,6 +4671,13 @@ class ColumnClause( # expect the columns of tables and subqueries to be leaf nodes. return [] + @property + def entity_namespace(self): + if self.table is not None: + return self.table.entity_namespace + else: + return super(ColumnClause, self).entity_namespace + @HasMemoized.memoized_attribute def _from_objects(self): t = self.table |