summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/functions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-05-01 08:41:09 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-05-01 11:54:21 -0400
commit5cde12d816b8b32719cee377677667150df07c48 (patch)
tree2bfe72c72617f617d80301d08e19a845211fad9f /lib/sqlalchemy/sql/functions.py
parenta47c158a9a3b1104698fc0bff47ca58d67cb9191 (diff)
downloadsqlalchemy-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/functions.py')
-rw-r--r--lib/sqlalchemy/sql/functions.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index 02ed55100..0aa870ce4 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -15,6 +15,7 @@ from . import roles
from . import schema
from . import sqltypes
from . import util as sqlutil
+from .base import _entity_namespace
from .base import ColumnCollection
from .base import Executable
from .base import Generative
@@ -618,6 +619,16 @@ class FunctionElement(Executable, ColumnElement, FromClause, Generative):
else:
return super(FunctionElement, self).self_group(against=against)
+ @property
+ def entity_namespace(self):
+ """overrides FromClause.entity_namespace as functions are generally
+ column expressions and not FromClauses.
+
+ """
+ # ideally functions would not be fromclauses but we failed to make
+ # this adjustment in 1.4
+ return _entity_namespace(self.clause_expr)
+
class FunctionAsBinary(BinaryExpression):
_traverse_internals = [