diff options
author | Federico Caselli <cfederico87@gmail.com> | 2020-03-07 19:17:07 +0100 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-07 17:50:45 -0500 |
commit | eda6dbbf387def2063d1b6719b64b20f9e7f2ab4 (patch) | |
tree | 4af5f41edfac169b0fdc6d6cab0fce4e8bf776cf /lib/sqlalchemy/orm/state.py | |
parent | 851fb8f5a661c66ee76308181118369c8c4df9e0 (diff) | |
download | sqlalchemy-eda6dbbf387def2063d1b6719b64b20f9e7f2ab4.tar.gz |
Simplified module pre-loading strategy and made it linter friendly
Introduced a modules registry to register modules that should be lazily loaded
in the package init. This ensures that they are in the system module cache,
avoiding potential thread safety issues as when importing them directly
in the function that uses them. The module registry is used to obtain
these modules directly, ensuring that the all the lazily loaded modules
are resolved at the proper time
This replaces dependency_for decorator and the dependencies decorator logic,
removing the need to pass the resolved modules as arguments of the
decodated functions and removes possible errors caused by linters.
Fixes: #4689
Fixes: #4656
Change-Id: I2e291eba4297867fc0ddb5d875b9f7af34751d01
Diffstat (limited to 'lib/sqlalchemy/orm/state.py')
-rw-r--r-- | lib/sqlalchemy/orm/state.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 41f878b77..91bf57ab9 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -227,11 +227,11 @@ class InstanceState(interfaces.InspectionAttrInfo): return self.key is not None and not self._attached @property - @util.dependencies("sqlalchemy.orm.session") - def _attached(self, sessionlib): + @util.preload_module("sqlalchemy.orm.session") + def _attached(self): return ( self.session_id is not None - and self.session_id in sessionlib._sessions + and self.session_id in util.preloaded.orm_session._sessions ) def _track_last_known_value(self, key): @@ -247,8 +247,8 @@ class InstanceState(interfaces.InspectionAttrInfo): self._last_known_values[key] = NO_VALUE @property - @util.dependencies("sqlalchemy.orm.session") - def session(self, sessionlib): + @util.preload_module("sqlalchemy.orm.session") + def session(self): """Return the owning :class:`.Session` for this instance, or ``None`` if none available. @@ -260,7 +260,7 @@ class InstanceState(interfaces.InspectionAttrInfo): fully detached under normal circumstances. """ - return sessionlib._state_session(self) + return util.preloaded.orm_session._state_session(self) @property def object(self): |