summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-12-16 17:06:43 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-07-03 23:39:51 -0400
commit3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c (patch)
tree1041bccb37422f526dccb5b1e57ffad1c702549b /lib/sqlalchemy/orm/query.py
parent5060043e8e95ab0aab5f63ed288c1426c46da66e (diff)
downloadsqlalchemy-3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c.tar.gz
introduce deferred lambdas
The coercions system allows us to add in lambdas as arguments to Core and ORM elements without changing them at all. By allowing the lambda to produce a deterministic cache key where we can also cheat and yank out literal parameters means we can move towards having 90% of "baked" functionality in a clearer way right in Core / ORM. As a second step, we can have whole statements inside the lambda, and can then add generation with __add__(), so then we have 100% of "baked" functionality with full support of ad-hoc literal values. Adds some more short_selects tests for the moment for comparison. Other tweaks inside cache key generation as we're trying to approach a certain level of performance such that we can remove the use of "baked" from the loader strategies. As we have not yet closed #4639, however the caching feature has been fully integrated as of b0cfa7379cf8513a821a3dbe3028c4965d9f85bd, we will also add complete caching documentation here and close that issue as well. Closes: #4639 Fixes: #5380 Change-Id: If91f61527236fd4d7ae3cad1f24c38be921c90ba
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
-rw-r--r--lib/sqlalchemy/orm/query.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 336b7d9aa..1ca65c733 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -20,6 +20,7 @@ database to return iterable result sets.
"""
import itertools
import operator
+import types
from . import attributes
from . import exc as orm_exc
@@ -2229,7 +2230,8 @@ class Query(
# non legacy argument form
_props = [(target,)]
elif not legacy and isinstance(
- target, (expression.Selectable, type, AliasedClass,)
+ target,
+ (expression.Selectable, type, AliasedClass, types.FunctionType),
):
# non legacy argument form
_props = [(target, onclause)]
@@ -2284,7 +2286,13 @@ class Query(
legacy=True,
apply_propagate_attrs=self,
),
- prop[1] if len(prop) == 2 else None,
+ (
+ coercions.expect(roles.OnClauseRole, prop[1])
+ if not isinstance(prop[1], str)
+ else prop[1]
+ )
+ if len(prop) == 2
+ else None,
None,
{
"isouter": isouter,