check for autocommit=True as create_engine() options, what's going on here exactly?

Issue #3200 resolved
Michael Bayer
repo owner created an issue

need to understand why using execution_options() method works and the built in dict does not

from sqlalchemy.engine import create_engine

e = create_engine("mysql://scott:tiger@localhost/test", execution_options={"autocommit": True})

c = e.connect()
 File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/strategies.py", line 165, in first_connect
    dialect.initialize(c)
  File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/mysql/base.py", line 2431, in initialize
    self._detect_ansiquotes(connection)
  File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/mysql/base.py", line 2697, in _detect_ansiquotes
    connection.execute("SHOW VARIABLES LIKE 'sql_mode'"),
  File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py", line 721, in execute
    return self._execute_text(object, multiparams, params)
  File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py", line 870, in _execute_text
    statement, parameters
  File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py", line 997, in _execute_context
    self._commit_impl(autocommit=True)
  File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py", line 530, in _commit_impl
    self.connection._reset_agent is self.__transaction:
AttributeError: 'Connection' object has no attribute '_reset_agent'

Comments (5)

  1. Michael Bayer reporter

    because execution_options() returns a new OptionEngine separate from the original, so that's not the one where the dialect initialize occurs. an engine where the arg is passed directly or updated with update_execution_options(), those are fixed in the Engine that is passed in for initialize.

  2. Michael Bayer reporter
    • The execution options passed to an :class:.Engine either via :paramref:.create_engine.execution_options or :meth:.Engine.update_execution_options are not passed to the special :class:.Connection used to initialize the dialect within the "first connect" event; dialects will usually perform their own queries in this phase, and none of the current available options should be applied here. In particular, the "autocommit" option was causing an attempt to autocommit within this initial connect which would fail with an AttributeError due to the non-standard state of the :class:.Connection. fixes #3200

    → <<cset 119674dd250d>>

  3. Michael Bayer reporter
    • The execution options passed to an :class:.Engine either via :paramref:.create_engine.execution_options or :meth:.Engine.update_execution_options are not passed to the special :class:.Connection used to initialize the dialect within the "first connect" event; dialects will usually perform their own queries in this phase, and none of the current available options should be applied here. In particular, the "autocommit" option was causing an attempt to autocommit within this initial connect which would fail with an AttributeError due to the non-standard state of the :class:.Connection. fixes #3200

    → <<cset 96e17a14c5f2>>

  4. Log in to comment