summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/engine/result.py11
-rw-r--r--lib/sqlalchemy/orm/context.py42
-rw-r--r--lib/sqlalchemy/orm/session.py18
3 files changed, 49 insertions, 22 deletions
diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index 60474c0ed..3c2e682be 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -1054,6 +1054,17 @@ class Result(_WithKeys, ResultInternal):
column of the first row, use the :meth:`.Result.scalar` method,
or combine :meth:`.Result.scalars` and :meth:`.Result.first`.
+ Additionally, in contrast to the behavior of the legacy ORM
+ :meth:`_orm.Query.first` method, **no limit is applied** to the
+ SQL query which was invoked to produce this :class:`_engine.Result`;
+ for a DBAPI driver that buffers results in memory before yielding
+ rows, all rows will be sent to the Python process and all but
+ the first row will be discarded.
+
+ .. seealso::
+
+ :ref:`migration_20_unify_select`
+
:return: a :class:`.Row` object, or None
if no rows remain.
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py
index 83b6586cc..9318bb163 100644
--- a/lib/sqlalchemy/orm/context.py
+++ b/lib/sqlalchemy/orm/context.py
@@ -417,7 +417,10 @@ class ORMFromStatementCompileState(ORMCompileState):
)
_QueryEntity.to_compile_state(
- self, statement_container._raw_columns, self._entities
+ self,
+ statement_container._raw_columns,
+ self._entities,
+ is_current_entities=True,
)
self.current_path = statement_container._compile_options._current_path
@@ -590,6 +593,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
self,
memoized_entities._raw_columns,
[],
+ is_current_entities=False,
)
for memoized_entities in (
select_statement._memoized_select_entities
@@ -597,7 +601,10 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
}
_QueryEntity.to_compile_state(
- self, select_statement._raw_columns, self._entities
+ self,
+ select_statement._raw_columns,
+ self._entities,
+ is_current_entities=True,
)
self.current_path = select_statement._compile_options._current_path
@@ -839,7 +846,9 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
# entities will also set up polymorphic adapters for mappers
# that have with_polymorphic configured
- _QueryEntity.to_compile_state(self, query._raw_columns, self._entities)
+ _QueryEntity.to_compile_state(
+ self, query._raw_columns, self._entities, is_current_entities=True
+ )
return self
@classmethod
@@ -2278,13 +2287,18 @@ class _QueryEntity(object):
use_id_for_hash = False
@classmethod
- def to_compile_state(cls, compile_state, entities, entities_collection):
+ def to_compile_state(
+ cls, compile_state, entities, entities_collection, is_current_entities
+ ):
for idx, entity in enumerate(entities):
if entity._is_lambda_element:
if entity._is_sequence:
cls.to_compile_state(
- compile_state, entity._resolved, entities_collection
+ compile_state,
+ entity._resolved,
+ entities_collection,
+ is_current_entities,
)
continue
else:
@@ -2294,7 +2308,10 @@ class _QueryEntity(object):
if entity.is_selectable:
if "parententity" in entity._annotations:
_MapperEntity(
- compile_state, entity, entities_collection
+ compile_state,
+ entity,
+ entities_collection,
+ is_current_entities,
)
else:
_ColumnEntity._for_columns(
@@ -2343,12 +2360,15 @@ class _MapperEntity(_QueryEntity):
"_polymorphic_discriminator",
)
- def __init__(self, compile_state, entity, entities_collection):
+ def __init__(
+ self, compile_state, entity, entities_collection, is_current_entities
+ ):
entities_collection.append(self)
- if compile_state._primary_entity is None:
- compile_state._primary_entity = self
- compile_state._has_mapper_entities = True
- compile_state._has_orm_entities = True
+ if is_current_entities:
+ if compile_state._primary_entity is None:
+ compile_state._primary_entity = self
+ compile_state._has_mapper_entities = True
+ compile_state._has_orm_entities = True
entity = entity._annotations["parententity"]
entity._post_inspect
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 8302f70d6..fdef99370 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1049,17 +1049,13 @@ class Session(_SessionClassMethods):
:param enable_baked_queries: defaults to ``True``. A flag consumed
by the :mod:`sqlalchemy.ext.baked` extension to determine if
"baked queries" should be cached, as is the normal operation
- of this extension. When set to ``False``, all caching is disabled,
- including baked queries defined by the calling application as
- well as those used internally. Setting this flag to ``False``
- can significantly reduce memory use, however will also degrade
- performance for those areas that make use of baked queries
- (such as relationship loaders). Additionally, baked query
- logic in the calling application or potentially within the ORM
- that may be malfunctioning due to cache key collisions or similar
- can be flagged by observing if this flag resolves the issue.
-
- .. versionadded:: 1.2
+ of this extension. When set to ``False``, caching as used by
+ this particular extension is disabled.
+
+ .. versionchanged:: 1.4 The ``sqlalchemy.ext.baked`` extension is
+ legacy and is not used by any of SQLAlchemy's internals. This
+ flag therefore only affects applications that are making explicit
+ use of this extension within their own code.
:param expire_on_commit: Defaults to ``True``. When ``True``, all
instances will be fully expired after each :meth:`~.commit`,