summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/context.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-06-26 16:15:19 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-07-08 11:05:11 -0400
commit91f376692d472a5bf0c4b4033816250ec1ce3ab6 (patch)
tree31f7f72cbe981eb73ed0ba11808d4fb5ae6b7d51 /lib/sqlalchemy/orm/context.py
parent3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c (diff)
downloadsqlalchemy-91f376692d472a5bf0c4b4033816250ec1ce3ab6.tar.gz
Add future=True to create_engine/Session; unify select()
Several weeks of using the future_select() construct has led to the proposal there be just one select() construct again which features the new join() method, and otherwise accepts both the 1.x and 2.x argument styles. This would make migration simpler and reduce confusion. However, confusion may be increased by the fact that select().join() is different Current thinking is we may be better off with a few hard behavioral changes to old and relatively unknown APIs rather than trying to play both sides within two extremely similar but subtly different APIs. At the moment, the .join() thing seems to be the only behavioral change that occurs without the user taking any explicit steps. Session.execute() will still behave the old way as we are adding a future flag. This change also adds the "future" flag to Session() and session.execute(), so that interpretation of the incoming statement, as well as that the new style result is returned, does not occur for existing applications unless they add the use of this flag. The change in general is moving the "removed in 2.0" system further along where we want the test suite to fully pass even if the SQLALCHEMY_WARN_20 flag is set. Get many tests to pass when SQLALCHEMY_WARN_20 is set; this should be ongoing after this patch merges. Improve the RemovedIn20 warning; these are all deprecated "since" 1.4, so ensure that's what the messages read. Make sure the inforamtion link is on all warnings. Add deprecation warnings for parameters present and add warnings to all FromClause.select() types of methods. Fixes: #5379 Fixes: #5284 Change-Id: I765a0b912b3dcd0e995426427d8bb7997cbffd51 References: #5159
Diffstat (limited to 'lib/sqlalchemy/orm/context.py')
-rw-r--r--lib/sqlalchemy/orm/context.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py
index 09163d4e9..d5f001db1 100644
--- a/lib/sqlalchemy/orm/context.py
+++ b/lib/sqlalchemy/orm/context.py
@@ -25,6 +25,7 @@ from ..sql import expression
from ..sql import roles
from ..sql import util as sql_util
from ..sql import visitors
+from ..sql.base import _entity_namespace_key
from ..sql.base import _select_iterables
from ..sql.base import CacheableOptions
from ..sql.base import CompileState
@@ -241,8 +242,6 @@ class ORMCompileState(CompileState):
# were passed to session.execute:
# session.execute(legacy_select([User.id, User.name]))
# see test_query->test_legacy_tuple_old_select
- if not statement._is_future:
- return result
load_options = execution_options.get(
"_sa_orm_load_options", QueryContext.default_load_options
@@ -399,6 +398,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
compound_eager_adapter = None
correlate = None
+ correlate_except = None
_where_criteria = ()
_having_criteria = ()
@@ -406,9 +406,6 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
def create_for_statement(cls, statement, compiler, **kw):
"""compiler hook, we arrive here from compiler.visit_select() only."""
- if not statement._is_future:
- return SelectState(statement, compiler, **kw)
-
if compiler is not None:
toplevel = not compiler.stack
compiler._rewrites_selected_columns = True
@@ -592,6 +589,13 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
for s in query._correlate
)
)
+ elif query._correlate_except:
+ self.correlate_except = tuple(
+ util.flatten_iterator(
+ sql_util.surface_selectables(s) if s is not None else None
+ for s in query._correlate_except
+ )
+ )
elif not query._auto_correlate:
self.correlate = (None,)
@@ -827,6 +831,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
hints=self.select_statement._hints,
statement_hints=self.select_statement._statement_hints,
correlate=self.correlate,
+ correlate_except=self.correlate_except,
**self._select_args
)
@@ -902,6 +907,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
hints=self.select_statement._hints,
statement_hints=self.select_statement._statement_hints,
correlate=self.correlate,
+ correlate_except=self.correlate_except,
**self._select_args
)
@@ -921,6 +927,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
hints,
statement_hints,
correlate,
+ correlate_except,
limit_clause,
offset_clause,
distinct,
@@ -972,6 +979,11 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
if correlate:
statement.correlate.non_generative(statement, *correlate)
+ if correlate_except:
+ statement.correlate_except.non_generative(
+ statement, *correlate_except
+ )
+
return statement
def _adapt_polymorphic_element(self, element):
@@ -1222,7 +1234,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
# string given, e.g. query(Foo).join("bar").
# we look to the left entity or what we last joined
# towards
- onclause = sql.util._entity_namespace_key(
+ onclause = _entity_namespace_key(
inspect(self._joinpoint_zero()), onclause
)
@@ -1243,9 +1255,7 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
info = inspect(jp0)
if getattr(info, "mapper", None) is onclause._parententity:
- onclause = sql.util._entity_namespace_key(
- info, onclause.key
- )
+ onclause = _entity_namespace_key(info, onclause.key)
# legacy ^^^^^^^^^^^^^^^^^^^^^^^^^^^
if isinstance(onclause, interfaces.PropComparator):