diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-12-20 14:09:27 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-12-20 14:09:27 +0000 |
| commit | 1221407282f8285318daa34cbe6bd2b13d423212 (patch) | |
| tree | b843c2124a7d0f1bab1301a0fb053530baea48b4 /lib/sqlalchemy | |
| parent | b301dd2d20f2da66f4eb69527ba2642da34c630d (diff) | |
| parent | 736f93473d351cf3ab7680e4ed373e19f997b3bb (diff) | |
| download | sqlalchemy-1221407282f8285318daa34cbe6bd2b13d423212.tar.gz | |
Merge "use load_scalar_attributes() for undefer" into main
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/loading.py | 18 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/strategies.py | 17 |
2 files changed, 7 insertions, 28 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index d6ee9b7a7..a37d83cfe 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -16,7 +16,6 @@ as well as some of the attribute loading strategies. from . import attributes from . import exc as orm_exc from . import path_registry -from . import strategy_options from .base import _DEFER_FOR_STATE from .base import _RAISE_FOR_STATE from .base import _SET_DEFERRED_EXPIRED @@ -1386,25 +1385,14 @@ def load_scalar_attributes(mapper, state, attribute_names, passive): attribute_names = attribute_names.intersection(mapper.attrs.keys()) if mapper.inherits and not mapper.concrete: - # because we are using Core to produce a select() that we - # pass to the Query, we aren't calling setup() for mapped - # attributes; in 1.0 this means deferred attrs won't get loaded - # by default statement = mapper._optimized_get_statement(state, attribute_names) if statement is not None: - # this was previously aliased(mapper, statement), however, - # statement is a select() and Query's coercion now raises for this - # since you can't "select" from a "SELECT" statement. only - # from_statement() allows this. - # note: using from_statement() here means there is an adaption - # with adapt_on_names set up. the other option is to make the - # aliased() against a subquery which affects the SQL. from .query import FromStatement - stmt = FromStatement(mapper, statement).options( - strategy_options.Load(mapper).undefer("*") - ) + # undefer() isn't needed here because statement has the + # columns needed already, this implicitly undefers that column + stmt = FromStatement(mapper, statement) result = load_on_ident( session, diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index ff4ac9d33..51e81e104 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -24,6 +24,7 @@ from . import util as orm_util from .base import _DEFER_FOR_STATE from .base import _RAISE_FOR_STATE from .base import _SET_DEFERRED_EXPIRED +from .base import PASSIVE_OFF from .context import _column_descriptions from .context import ORMCompileState from .context import QueryContext @@ -512,19 +513,9 @@ class DeferredColumnLoader(LoaderStrategy): if self.raiseload: self._invoke_raise_load(state, passive, "raise") - if ( - loading.load_on_ident( - session, - sql.select(localparent).set_label_style( - LABEL_STYLE_TABLENAME_PLUS_COL - ), - state.key, - only_load_props=group, - refresh_state=state, - ) - is None - ): - raise orm_exc.ObjectDeletedError(state) + loading.load_scalar_attributes( + state.mapper, state, set(group), PASSIVE_OFF + ) return attributes.ATTR_WAS_SET |
