summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/relationships.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-01-30 11:55:22 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-02-01 16:35:35 -0500
commit5ec5b0a6c7b618bba7926e21f77be9557973860f (patch)
tree2d680370e2c8551d92b04ad2155eff5fd95ecb7a /lib/sqlalchemy/orm/relationships.py
parent532026f97f402d6673cd9746f1a7daee99327a68 (diff)
downloadsqlalchemy-5ec5b0a6c7b618bba7926e21f77be9557973860f.tar.gz
reorganize mapper compile/teardown under registry
Mapper "configuration", which occurs within the :func:`_orm.configure_mappers` function, is now organized to be on a per-registry basis. This allows for example the mappers within a certain declarative base to be configured, but not those of another base that is also present in memory. The goal is to provide a means of reducing application startup time by only running the "configure" process for sets of mappers that are needed. This also adds the :meth:`_orm.registry.configure` method that will run configure for the mappers local in a particular registry only. Fixes: #5897 Change-Id: I14bd96982d6d46e241bd6baa2cf97471d21e7caa
Diffstat (limited to 'lib/sqlalchemy/orm/relationships.py')
-rw-r--r--lib/sqlalchemy/orm/relationships.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py
index 41c3a5e53..1a0140914 100644
--- a/lib/sqlalchemy/orm/relationships.py
+++ b/lib/sqlalchemy/orm/relationships.py
@@ -1658,11 +1658,8 @@ class RelationshipProperty(StrategizedProperty):
return _orm_annotate(self.__negated_contains_or_equals(other))
@util.memoized_property
- @util.preload_module("sqlalchemy.orm.mapper")
def property(self):
- mapperlib = util.preloaded.orm_mapper
- if mapperlib.Mapper._new_mappers:
- mapperlib.Mapper._configure_all()
+ self.prop.parent._check_configure()
return self.prop
def _with_parent(self, instance, alias_secondary=True, from_entity=None):
@@ -2130,9 +2127,9 @@ class RelationshipProperty(StrategizedProperty):
return self.entity.mapper
def do_init(self):
-
self._check_conflicts()
self._process_dependent_arguments()
+ self._setup_registry_dependencies()
self._setup_join_conditions()
self._check_cascade_settings(self._cascade)
self._post_init()
@@ -2141,6 +2138,11 @@ class RelationshipProperty(StrategizedProperty):
super(RelationshipProperty, self).do_init()
self._lazy_strategy = self._get_strategy((("lazy", "select"),))
+ def _setup_registry_dependencies(self):
+ self.parent.mapper.registry._set_depends_on(
+ self.entity.mapper.registry
+ )
+
def _process_dependent_arguments(self):
"""Convert incoming configuration arguments to their
proper form.
@@ -3391,9 +3393,7 @@ class JoinCondition(object):
_track_overlapping_sync_targets = weakref.WeakKeyDictionary()
- @util.preload_module("sqlalchemy.orm.mapper")
def _warn_for_conflicting_sync_targets(self):
- mapperlib = util.preloaded.orm_mapper
if not self.support_sync:
return
@@ -3424,7 +3424,7 @@ class JoinCondition(object):
for pr, fr_ in prop_to_from.items():
if (
- pr.mapper in mapperlib._mapper_registry
+ not pr.mapper._dispose_called
and pr not in self.prop._reverse_property
and pr.key not in self.prop._overlaps
and self.prop.key not in pr._overlaps