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/query.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/query.py')
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 830cede93..796ebe3ac 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -26,7 +26,6 @@ from . import exc as orm_exc from . import interfaces from . import loading from . import persistence -from . import properties from .base import _assertions from .base import _entity_descriptor from .base import _is_aliased_class @@ -1120,6 +1119,7 @@ class Query(Generative): """ self._invoke_all_eagers = value + @util.preload_module("sqlalchemy.orm.relationships") def with_parent(self, instance, property=None, from_entity=None): # noqa """Add filtering criterion that relates the given instance to a child object or collection, using its attribute state @@ -1146,6 +1146,7 @@ class Query(Generative): "zero" entity of the :class:`.Query` itself. """ + relationships = util.preloaded.orm_relationships if from_entity: entity_zero = inspect(from_entity) @@ -1157,7 +1158,7 @@ class Query(Generative): for prop in mapper.iterate_properties: if ( - isinstance(prop, properties.RelationshipProperty) + isinstance(prop, relationships.RelationshipProperty) and prop.mapper is entity_zero.mapper ): property = prop # noqa @@ -4089,7 +4090,7 @@ class Query(Generative): class LockmodeArg(ForUpdateArg): @classmethod - def parse_legacy_query(self, mode): + def parse_legacy_query(cls, mode): if mode in (None, False): return None |