summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/loading.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-12-15 15:00:28 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-12-19 13:49:38 -0500
commit736f93473d351cf3ab7680e4ed373e19f997b3bb (patch)
treef29449dc6e8ffb55177d86aaaa241948d1eb413a /lib/sqlalchemy/orm/loading.py
parenta91df497d8d78292b0b5e7f79656b3f82d7de4f7 (diff)
downloadsqlalchemy-736f93473d351cf3ab7680e4ed373e19f997b3bb.tar.gz
use load_scalar_attributes() for undefer
At some point, undeferral of attributes started emitting a full ORM query for the entity, including that subclass columns would use a JOIN. Seems to be at least in 1.3 / 1.4 and possibly earlier. This JOINs to the superclass table unnecessarily. Use load_scalar_attributes() here which should handle the whole thing and emits a more efficient query for joined inheritance. As this behavior seems to have been throughout 1.3 and 1.4 at least, targeting at 2.0 is likely best. Fixes: #7463 Change-Id: Ie4bae767747bba0d03fb13eaff579d4bab0b1bc2
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r--lib/sqlalchemy/orm/loading.py18
1 files changed, 3 insertions, 15 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,