Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

samples.samples.autocommit_test: test_enable_autocommit_mode failed #254

Closed

Description

@flaky-bot

This test failed!

To configure my behavior, see the Flaky Bot documentation.

If I'm commenting on this issue too often, add the flakybot: quiet label and
I will stop commenting.


commit: 01d3b06
buildURL: Build Status, Sponge
status: failed

Test output
self = 
sql = "INSERT INTO Singers (SingerId, FirstName, LastName) VALUES\n            (12, 'Melissa', 'Garcia'),\n            (13, 'Russell', 'Morales'),\n            (14, 'Jacqueline', 'Long'),\n            (15, 'Dylan', 'Shaw')"
args = None
def execute(self, sql, args=None):
    """Prepares and executes a Spanner database operation.

    :type sql: str
    :param sql: A SQL query statement.

    :type args: list
    :param args: Additional parameters to supplement the SQL query.
    """
    if not self.connection:
        raise ProgrammingError("Cursor is not connected to the database")

    self._raise_if_closed()

    self._result_set = None

    # Classify whether this is a read-only SQL statement.
    try:
        classification = parse_utils.classify_stmt(sql)
        if classification == parse_utils.STMT_DDL:
            self.connection._ddl_statements.append(sql)
            return

        # For every other operation, we've got to ensure that
        # any prior DDL statements were run.
        # self._run_prior_DDL_statements()
      self.connection.run_prior_DDL_statements()

../../google/cloud/spanner_dbapi/cursor.py:190:


self = <google.cloud.spanner_dbapi.connection.Connection object at 0x7f5b2b1b6750>

def run_prior_DDL_statements(self):
    self._raise_if_closed()

    if self._ddl_statements:
        ddl_statements = self._ddl_statements
        self._ddl_statements = []
      return self.database.update_ddl(ddl_statements).result()

../../google/cloud/spanner_dbapi/connection.py:281:


self = <google.api_core.operation.Operation object at 0x7f5b2b0fef10>
timeout = None, retry = <google.api_core.retry.Retry object at 0x7f5b2b4a6c50>

def result(self, timeout=None, retry=DEFAULT_RETRY):
    """Get the result of the operation, blocking if necessary.

    Args:
        timeout (int):
            How long (in seconds) to wait for the operation to complete.
            If None, wait indefinitely.

    Returns:
        google.protobuf.Message: The Operation's result.

    Raises:
        google.api_core.GoogleAPICallError: If the operation errors or if
            the timeout is reached before the operation completes.
    """
    kwargs = {} if retry is DEFAULT_RETRY else {"retry": retry}
    self._blocking_poll(timeout=timeout, **kwargs)

    if self._exception is not None:
        # pylint: disable=raising-bad-type
        # Pylint doesn't recognize that this is valid in this case.
      raise self._exception

E google.api_core.exceptions.FailedPrecondition: 400 Duplicate name in schema: Singers.

.nox/py-3-7/lib/python3.7/site-packages/google/api_core/future/polling.py:134: FailedPrecondition

During handling of the above exception, another exception occurred:

capsys = <_pytest.capture.CaptureFixture object at 0x7f5b2b0751d0>
database = <google.cloud.spanner_v1.database.Database object at 0x7f5b2b024d90>

@RetryErrors(exception=Aborted, max_tries=2)
def test_enable_autocommit_mode(capsys, database):
    connection = connect(INSTANCE_ID, DATABASE_ID)
    cursor = connection.cursor()

    with mock.patch(
        "google.cloud.spanner_dbapi.connection.Cursor", return_value=cursor,
    ):
      autocommit.enable_autocommit_mode(INSTANCE_ID, DATABASE_ID)

autocommit_test.py:62:


autocommit.py:36: in enable_autocommit_mode
(15, 'Dylan', 'Shaw')"""


self = <google.cloud.spanner_dbapi.cursor.Cursor object at 0x7f5b2b11bb50>
sql = "INSERT INTO Singers (SingerId, FirstName, LastName) VALUES\n (12, 'Melissa', 'Garcia'),\n (13, 'Russell', 'Morales'),\n (14, 'Jacqueline', 'Long'),\n (15, 'Dylan', 'Shaw')"
args = None

def execute(self, sql, args=None):
    """Prepares and executes a Spanner database operation.

    :type sql: str
    :param sql: A SQL query statement.

    :type args: list
    :param args: Additional parameters to supplement the SQL query.
    """
    if not self.connection:
        raise ProgrammingError("Cursor is not connected to the database")

    self._raise_if_closed()

    self._result_set = None

    # Classify whether this is a read-only SQL statement.
    try:
        classification = parse_utils.classify_stmt(sql)
        if classification == parse_utils.STMT_DDL:
            self.connection._ddl_statements.append(sql)
            return

        # For every other operation, we've got to ensure that
        # any prior DDL statements were run.
        # self._run_prior_DDL_statements()
        self.connection.run_prior_DDL_statements()

        if not self.connection.autocommit:
            if classification == parse_utils.STMT_UPDATING:
                sql = parse_utils.ensure_where_clause(sql)

            if classification != parse_utils.STMT_INSERT:
                sql, args = sql_pyformat_args_to_spanner(sql, args or None)

            statement = Statement(
                sql,
                args,
                get_param_types(args or None)
                if classification != parse_utils.STMT_INSERT
                else {},
                ResultsChecksum(),
                classification == parse_utils.STMT_INSERT,
            )
            (self._result_set, self._checksum,) = self.connection.run_statement(
                statement
            )
            self._itr = PeekIterator(self._result_set)
            return

        if classification == parse_utils.STMT_NON_UPDATING:
            self._handle_DQL(sql, args or None)
        elif classification == parse_utils.STMT_INSERT:
            _helpers.handle_insert(self.connection, sql, args or None)
        else:
            self.connection.database.run_in_transaction(
                self._do_execute_update, sql, args or None
            )
    except (AlreadyExists, FailedPrecondition) as e:
      raise IntegrityError(e.details if hasattr(e, "details") else e)

E google.cloud.spanner_dbapi.exceptions.IntegrityError: 400 Duplicate name in schema: Singers.

../../google/cloud/spanner_dbapi/cursor.py:223: IntegrityError

Activity

  1. added
    flakybot: issueAn issue filed by the Flaky Bot. Should not be added manually.
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Mar 7, 2021
  2. added
    api: spannerIssues related to the googleapis/python-spanner API.
    samplesIssues that are directly related to samples.
    on Mar 7, 2021
  3. added
    flakybot: flakyTells the Flaky Bot not to close or comment on this issue.
    on Mar 7, 2021
  4. flaky-bot commented on Mar 7, 2021

    @flaky-bot
    Author

    Looks like this issue is flaky. 😟

    I'm going to leave this open and stop commenting.

    A human should fix and close this.


    When run at the same commit (01d3b06), this test passed in one build (Build Status, Sponge) and failed in another build (Build Status, Sponge).

  5. larkee commented on Mar 8, 2021

    @larkee
    Contributor

    The fix in #214 did not consider that there are multiple transactions being executed. Previously the test would flake if a transaction was aborted. Now the test will flake if the second transaction is aborted.

    Executing a DML statement to drop the Singers table in test_enable_autocommit_mode before executing the sample should resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: spannerIssues related to the googleapis/python-spanner API.flakybot: flakyTells the Flaky Bot not to close or comment on this issue.flakybot: issueAn issue filed by the Flaky Bot. Should not be added manually.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.samplesIssues that are directly related to samples.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions