diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2020-05-29 21:45:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-05-29 21:45:54 +0000 |
commit | cbfa1363d7201848a56e7209146e81b9c51aa8af (patch) | |
tree | 2ffb5b0b50670a10744d7ef562cef4074360f820 /lib | |
parent | 7ff6cf1eaa84f1387d60d4eb7ba752480a6bf567 (diff) | |
parent | 9272ae4f77d670bd2ff4c55f50bf47ad374e8319 (diff) | |
download | sqlalchemy-cbfa1363d7201848a56e7209146e81b9c51aa8af.tar.gz |
Merge "Remove loader option cycle"
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sqlalchemy/orm/context.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/loading.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/strategy_options.py | 31 |
3 files changed, 16 insertions, 24 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py index 09f3e7a12..5589f0e0c 100644 --- a/lib/sqlalchemy/orm/context.py +++ b/lib/sqlalchemy/orm/context.py @@ -117,11 +117,6 @@ class QueryContext(object): % ", ".join(compile_state._no_yield_pers) ) - def dispose(self): - self.attributes.clear() - self.load_options._refresh_state = None - self.load_options._lazy_loaded_from = None - class ORMCompileState(CompileState): class default_compile_options(CacheableOptions): diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 44ab7dd63..88d01eb0f 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -125,10 +125,6 @@ def instances(cursor, context): if not yield_per: break - context.dispose() - if not cursor.context.compiled.cache_key: - compile_state.attributes.clear() - result = ChunkedIteratorResult( row_metadata, chunks, source_supports_scalars=single_entity, raw=cursor ) diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index 5fca41ba6..a059c67ac 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -214,7 +214,13 @@ class Load(Generative, LoaderOption): compile_state.attributes.update(self.context) def _generate_path( - self, path, attr, for_strategy, wildcard_key, raiseerr=True + self, + path, + attr, + for_strategy, + wildcard_key, + raiseerr=True, + polymorphic_entity_context=None, ): existing_of_type = self._of_type self._of_type = None @@ -316,8 +322,11 @@ class Load(Generative, LoaderOption): ac = attr._of_type ext_info = of_type_info = inspect(ac) + if polymorphic_entity_context is None: + polymorphic_entity_context = self.context + existing = path.entity_path[prop].get( - self.context, "path_with_polymorphic" + polymorphic_entity_context, "path_with_polymorphic" ) if not ext_info.is_aliased_class: @@ -334,7 +343,7 @@ class Load(Generative, LoaderOption): ext_info = inspect(ac) path.entity_path[prop].set( - self.context, "path_with_polymorphic", ac + polymorphic_entity_context, "path_with_polymorphic", ac ) path = path[prop][ext_info] @@ -471,15 +480,14 @@ class Load(Generative, LoaderOption): def _set_for_path(self, context, path, replace=True, merge_opts=False): if merge_opts or not replace: - existing = path.get(self.context, "loader") - + existing = path.get(context, "loader") if existing: if merge_opts: existing.local_opts.update(self.local_opts) else: path.set(context, "loader", self) else: - existing = path.get(self.context, "loader") + existing = path.get(context, "loader") path.set(context, "loader", self) if existing and existing.is_opts_only: self.local_opts.update(existing.local_opts) @@ -862,15 +870,7 @@ class _UnboundLoad(Load): # tokens and populate into the Load(). loader = Load(path_element) - if context is not None: - # TODO: this creates a cycle with context.attributes. - # the current approach to mitigating this is the context / - # compile_state attributes are cleared out when a result - # is fetched. However, it would be nice if these attributes - # could be passed to all methods so that all the state - # gets set up without ever creating any assignments. - loader.context = context - else: + if context is None: context = loader.context loader.strategy = self.strategy @@ -887,6 +887,7 @@ class _UnboundLoad(Load): self.strategy if idx == len(start_path) - 1 else None, None, raiseerr, + polymorphic_entity_context=context, ): return |