diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-03 09:50:04 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-03 11:36:37 -0400 |
| commit | 7f0cb933f2b1979a8d781855618b7fd3bf280037 (patch) | |
| tree | 22957c23cdd906a929cd7e3daecacef5e0675513 /lib | |
| parent | 58ea81121877330e4bacd5aa4934c2742fc11693 (diff) | |
| download | sqlalchemy-7f0cb933f2b1979a8d781855618b7fd3bf280037.tar.gz | |
Inline a few ORM arguments, others
small changes
Change-Id: Id89a0651196c431d0aaf6935f5a4e7b12dd70c6c
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/context.py | 22 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 46 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 7 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/elements.py | 20 |
4 files changed, 48 insertions, 47 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py index ba30d203b..bd4074ea1 100644 --- a/lib/sqlalchemy/orm/context.py +++ b/lib/sqlalchemy/orm/context.py @@ -191,15 +191,9 @@ class ORMCompileState(CompileState): def orm_pre_session_exec( cls, session, statement, execution_options, bind_arguments ): - if execution_options: - # TODO: will have to provide public API to set some load - # options and also extract them from that API here, likely - # execution options - load_options = execution_options.get( - "_sa_orm_load_options", QueryContext.default_load_options - ) - else: - load_options = QueryContext.default_load_options + load_options = execution_options.get( + "_sa_orm_load_options", QueryContext.default_load_options + ) bind_arguments["clause"] = statement @@ -223,7 +217,9 @@ class ORMCompileState(CompileState): session._autoflush() @classmethod - def orm_setup_cursor_result(cls, session, bind_arguments, result): + def orm_setup_cursor_result( + cls, session, statement, execution_options, bind_arguments, result + ): execution_context = result.context compile_state = execution_context.compiled.compile_state @@ -231,13 +227,9 @@ 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 execution_context.compiled.statement._is_future: + if not statement._is_future: return result - execution_options = execution_context.execution_options - - # we are getting these right above in orm_pre_session_exec(), - # then getting them again right here. load_options = execution_options.get( "_sa_orm_load_options", QueryContext.default_load_options ) diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 25e224348..ee42419a2 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1297,17 +1297,16 @@ class Session(_SessionClassMethods): ) def _connection_for_bind(self, engine, execution_options=None, **kw): - self._autobegin() - - if self._transaction is not None: + if self._transaction is not None or self._autobegin(): return self._transaction._connection_for_bind( engine, execution_options ) - else: - conn = engine.connect(**kw) - if execution_options: - conn = conn.execution_options(**execution_options) - return conn + + assert self._transaction is None + conn = engine.connect(**kw) + if execution_options: + conn = conn.execution_options(**execution_options) + return conn def execute( self, @@ -1460,6 +1459,23 @@ class Session(_SessionClassMethods): compile_state_cls.orm_pre_session_exec( self, statement, execution_options, bind_arguments ) + + if self.dispatch.do_orm_execute: + skip_events = bind_arguments.pop("_sa_skip_events", False) + + if not skip_events: + orm_exec_state = ORMExecuteState( + self, + statement, + params, + execution_options, + bind_arguments, + ) + for fn in self.dispatch.do_orm_execute: + result = fn(orm_exec_state) + if result: + return result + else: compile_state_cls = None bind_arguments.setdefault("clause", statement) @@ -1468,18 +1484,6 @@ class Session(_SessionClassMethods): execution_options, {"future_result": True} ) - if self.dispatch.do_orm_execute: - skip_events = bind_arguments.pop("_sa_skip_events", False) - - if not skip_events: - orm_exec_state = ORMExecuteState( - self, statement, params, execution_options, bind_arguments - ) - for fn in self.dispatch.do_orm_execute: - result = fn(orm_exec_state) - if result: - return result - bind = self.get_bind(**bind_arguments) conn = self._connection_for_bind(bind, close_with_result=True) @@ -1487,7 +1491,7 @@ class Session(_SessionClassMethods): if compile_state_cls: result = compile_state_cls.orm_setup_cursor_result( - self, bind_arguments, result + self, statement, execution_options, bind_arguments, result ) return result diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 4bd19e04b..f4160b552 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2829,10 +2829,12 @@ class SQLCompiler(Compiled): if self.linting & COLLECT_CARTESIAN_PRODUCTS: from_linter = FromLinter({}, set()) + warn_linting = self.linting & WARN_LINTING if toplevel: self.from_linter = from_linter else: from_linter = None + warn_linting = False if froms: text += " \nFROM " @@ -2872,10 +2874,7 @@ class SQLCompiler(Compiled): if t: text += " \nWHERE " + t - if ( - self.linting & COLLECT_CARTESIAN_PRODUCTS - and self.linting & WARN_LINTING - ): + if warn_linting: from_linter.warn() if select._group_by_clauses: diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index fa2888a23..986bf134c 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -2189,6 +2189,10 @@ class BooleanClauseList(ClauseList, ColumnElement): has_continue_on = None convert_clauses = [] + + against = operators._asbool + lcc = 0 + for clause in clauses: if clause is continue_on: # instance of continue_on, like and_(x, y, True, z), store it @@ -2199,24 +2203,26 @@ class BooleanClauseList(ClauseList, ColumnElement): # instance of skip_on, e.g. and_(x, y, False, z), cancels # the rest out convert_clauses = [clause] + lcc = 1 break else: + if not lcc: + lcc = 1 + else: + against = operator + # techincally this would be len(convert_clauses) + 1 + # however this only needs to indicate "greater than one" + lcc = 2 convert_clauses.append(clause) if not convert_clauses and has_continue_on is not None: convert_clauses = [has_continue_on] + lcc = 1 - lcc = len(convert_clauses) - - if lcc > 1: - against = operator - else: - against = operators._asbool return lcc, [c.self_group(against=against) for c in convert_clauses] @classmethod def _construct(cls, operator, continue_on, skip_on, *clauses, **kw): - lcc, convert_clauses = cls._process_clauses_for_boolean( operator, continue_on, |
