summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/interfaces.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-12-01 17:24:27 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-05-24 11:54:08 -0400
commitdce8c7a125cb99fad62c76cd145752d5afefae36 (patch)
tree352dfa2c38005207ca64f45170bbba2c0f8c927e /lib/sqlalchemy/orm/interfaces.py
parent1502b5b3e4e4b93021eb927a6623f288ef006ba6 (diff)
downloadsqlalchemy-dce8c7a125cb99fad62c76cd145752d5afefae36.tar.gz
Unify Query and select() , move all processing to compile phase
Convert Query to do virtually all compile state computation in the _compile_context() phase, and organize it all such that a plain select() construct may also be used as the source of information in order to generate ORM query state. This makes it such that Query is not needed except for its additional methods like from_self() which are all to be deprecated. The construction of ORM state will occur beyond the caching boundary when the new execution model is integrated. future select() gains a working join() and filter_by() method. as we continue to rebase and merge each commit in the steps, callcounts continue to bump around. will have to look at the final result when it's all in. References: #5159 References: #4705 References: #4639 References: #4871 References: #5010 Change-Id: I19e05b3424b07114cce6c439b05198ac47f7ac10
Diffstat (limited to 'lib/sqlalchemy/orm/interfaces.py')
-rw-r--r--lib/sqlalchemy/orm/interfaces.py66
1 files changed, 63 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index 612724357..313f2fda8 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -36,6 +36,7 @@ from .. import inspect
from .. import inspection
from .. import util
from ..sql import operators
+from ..sql import roles
from ..sql import visitors
from ..sql.traversals import HasCacheKey
@@ -56,12 +57,25 @@ __all__ = (
"NOT_EXTENSION",
"LoaderStrategy",
"MapperOption",
+ "LoaderOption",
"MapperProperty",
"PropComparator",
"StrategizedProperty",
)
+class ORMColumnsClauseRole(roles.ColumnsClauseRole):
+ _role_name = "ORM mapped entity, aliased entity, or Column expression"
+
+
+class ORMEntityColumnsClauseRole(ORMColumnsClauseRole):
+ _role_name = "ORM mapped or aliased entity"
+
+
+class ORMFromClauseRole(roles.StrictFromClauseRole):
+ _role_name = "ORM mapped entity, aliased entity, or FROM expression"
+
+
class MapperProperty(
HasCacheKey, _MappedAttribute, InspectionAttr, util.MemoizedSlots
):
@@ -620,6 +634,8 @@ class StrategizedProperty(MapperProperty):
@classmethod
def _strategy_lookup(cls, requesting_property, *key):
+ requesting_property.parent._with_polymorphic_mappers
+
for prop_cls in cls.__mro__:
if prop_cls in cls._all_strategies:
strategies = cls._all_strategies[prop_cls]
@@ -646,8 +662,52 @@ class StrategizedProperty(MapperProperty):
)
+class LoaderOption(HasCacheKey):
+ """Describe a modification to an ORM statement at compilation time.
+
+ .. versionadded:: 1.4
+
+ """
+
+ __slots__ = ()
+
+ _is_legacy_option = False
+
+ propagate_to_loaders = False
+ """if True, indicate this option should be carried along
+ to "secondary" Query objects produced during lazy loads
+ or refresh operations.
+
+ """
+
+ def process_compile_state(self, compile_state):
+ """Apply a modification to a given :class:`.CompileState`."""
+
+ def _generate_path_cache_key(self, path):
+ """Used by the "baked lazy loader" to see if this option can be cached.
+
+ .. deprecated:: 2.0 this method is to suit the baked extension which
+ is itself not part of 2.0.
+
+ """
+ return False
+
+
+@util.deprecated_cls(
+ "1.4",
+ "The :class:`.MapperOption class is deprecated and will be removed "
+ "in a future release. ORM options now run within the compilation "
+ "phase and are based on the :class:`.LoaderOption` class which is "
+ "intended for internal consumption only. For "
+ "modifications to queries on a per-execution basis, the "
+ ":meth:`.before_execute` hook will now intercept ORM :class:`.Query` "
+ "objects before they are invoked",
+ constructor=None,
+)
class MapperOption(object):
- """Describe a modification to a Query."""
+ """Describe a modification to a Query"""
+
+ _is_legacy_option = True
propagate_to_loaders = False
"""if True, indicate this option should be carried along
@@ -663,7 +723,7 @@ class MapperOption(object):
"""same as process_query(), except that this option may not
apply to the given query.
- This is typically used during a lazy load or scalar refresh
+ This is typically applied during a lazy load or scalar refresh
operation to propagate options stated in the original Query to the
new Query being used for the load. It occurs for those options that
specify propagate_to_loaders=True.
@@ -770,7 +830,7 @@ class LoaderStrategy(object):
pass
def setup_query(
- self, context, query_entity, path, loadopt, adapter, **kwargs
+ self, compile_state, query_entity, path, loadopt, adapter, **kwargs
):
"""Establish column and other state for a given QueryContext.