diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-30 11:55:22 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-02-01 16:35:35 -0500 |
commit | 5ec5b0a6c7b618bba7926e21f77be9557973860f (patch) | |
tree | 2d680370e2c8551d92b04ad2155eff5fd95ecb7a /lib/sqlalchemy/orm/instrumentation.py | |
parent | 532026f97f402d6673cd9746f1a7daee99327a68 (diff) | |
download | sqlalchemy-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/instrumentation.py')
-rw-r--r-- | lib/sqlalchemy/orm/instrumentation.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index d2ff72180..c970bee22 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -129,7 +129,7 @@ class ClassManager(HasMemoized, dict): if mapper: self.mapper = mapper if registry: - self.registry = registry + registry._add_manager(self) if declarative_scan: self.declarative_scan = declarative_scan if expired_attribute_loader: @@ -278,11 +278,6 @@ class ClassManager(HasMemoized, dict): setattr(self.class_, self.MANAGER_ATTR, self) - def dispose(self): - """Disassociate this manager from its class.""" - - delattr(self.class_, self.MANAGER_ATTR) - @util.hybridmethod def manager_getter(self): return _default_manager_getter @@ -359,6 +354,9 @@ class ClassManager(HasMemoized, dict): if key in self.local_attrs: self.uninstrument_attribute(key) + if self.MANAGER_ATTR in self.class_.__dict__: + delattr(self.class_, self.MANAGER_ATTR) + def install_descriptor(self, key, inst): if key in (self.STATE_ATTR, self.MANAGER_ATTR): raise KeyError( @@ -496,7 +494,7 @@ class _SerializeManager(object): "Python process!" % self.class_, ) elif manager.is_mapped and not manager.mapper.configured: - manager.mapper._configure_all() + manager.mapper._check_configure() # setup _sa_instance_state ahead of time so that # unpickle events can access the object normally. @@ -538,10 +536,7 @@ class InstrumentationFactory(object): def unregister(self, class_): manager = manager_of_class(class_) manager.unregister() - manager.dispose() self.dispatch.class_uninstrument(class_) - if ClassManager.MANAGER_ATTR in class_.__dict__: - delattr(class_, ClassManager.MANAGER_ATTR) # this attribute is replaced by sqlalchemy.ext.instrumentation |