From c595dac73d6d50e84ad19dba8db25fac8c6490cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Thu, 5 Dec 2024 11:31:14 +0100 Subject: [PATCH 1/3] fix: allow setting staleness to same value in tx Repeatedly setting the staleness property of a connection in a transaction to the same value caused an error. This made it harder to use this property in SQLAlchemy. Updates https://github.com/googleapis/python-spanner-sqlalchemy/issues/495 --- google/cloud/spanner_dbapi/connection.py | 2 +- tests/unit/spanner_dbapi/test_connection.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/google/cloud/spanner_dbapi/connection.py b/google/cloud/spanner_dbapi/connection.py index 416bb2a959..cec6c64dac 100644 --- a/google/cloud/spanner_dbapi/connection.py +++ b/google/cloud/spanner_dbapi/connection.py @@ -277,7 +277,7 @@ def staleness(self, value): Args: value (dict): Staleness type and value. """ - if self._spanner_transaction_started: + if self._spanner_transaction_started and value != self._staleness: raise ValueError( "`staleness` option can't be changed while a transaction is in progress. " "Commit or rollback the current transaction and try again." diff --git a/tests/unit/spanner_dbapi/test_connection.py b/tests/unit/spanner_dbapi/test_connection.py index a07e94735f..4bee9e93c7 100644 --- a/tests/unit/spanner_dbapi/test_connection.py +++ b/tests/unit/spanner_dbapi/test_connection.py @@ -669,6 +669,20 @@ def test_staleness_inside_transaction(self): with self.assertRaises(ValueError): connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)} + def test_staleness_inside_transaction_same_value(self): + """ + Verify that setting `staleness` to the same value in a transaction is allowed. + """ + connection = self._make_connection() + connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)} + connection._spanner_transaction_started = True + connection._transaction = mock.Mock() + + connection.staleness = {"read_timestamp": datetime.datetime(2021, 9, 21)} + self.assertEqual( + connection.staleness, {"read_timestamp": datetime.datetime(2021, 9, 21)} + ) + def test_staleness_multi_use(self): """ Check that `staleness` option is correctly From 282a9828507ca3511b37c81a1c10f6c0622e79ad Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 5 Dec 2024 10:34:45 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- noxfile.py | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/noxfile.py b/noxfile.py index 905df735bc..f5a2761d73 100644 --- a/noxfile.py +++ b/noxfile.py @@ -33,7 +33,6 @@ LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" -DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12" UNIT_TEST_PYTHON_VERSIONS: List[str] = [ "3.7", @@ -235,34 +234,6 @@ def unit(session, protobuf_implementation): ) -@nox.session(python=DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION) -def mockserver(session): - # Install all test dependencies, then install this package in-place. - - constraints_path = str( - CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" - ) - # install_unittest_dependencies(session, "-c", constraints_path) - standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES - session.install(*standard_deps, "-c", constraints_path) - session.install("-e", ".", "-c", constraints_path) - - # Run py.test against the mockserver tests. - session.run( - "py.test", - "--quiet", - f"--junitxml=unit_{session.python}_sponge_log.xml", - "--cov=google", - "--cov=tests/unit", - "--cov-append", - "--cov-config=.coveragerc", - "--cov-report=", - "--cov-fail-under=0", - os.path.join("tests", "mockserver_tests"), - *session.posargs, - ) - - def install_systemtest_dependencies(session, *constraints): # Use pre-release gRPC for system tests. # Exclude version 1.52.0rc1 which has a known issue. From e3c6b374d8222279736c394b05d6dfa2d7c4fa32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Thu, 5 Dec 2024 11:38:36 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"=F0=9F=A6=89=20Updates=20from=20O?= =?UTF-8?q?wlBot=20post-processor"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 282a9828507ca3511b37c81a1c10f6c0622e79ad. --- noxfile.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/noxfile.py b/noxfile.py index f5a2761d73..905df735bc 100644 --- a/noxfile.py +++ b/noxfile.py @@ -33,6 +33,7 @@ LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" +DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12" UNIT_TEST_PYTHON_VERSIONS: List[str] = [ "3.7", @@ -234,6 +235,34 @@ def unit(session, protobuf_implementation): ) +@nox.session(python=DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION) +def mockserver(session): + # Install all test dependencies, then install this package in-place. + + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + # install_unittest_dependencies(session, "-c", constraints_path) + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, "-c", constraints_path) + session.install("-e", ".", "-c", constraints_path) + + # Run py.test against the mockserver tests. + session.run( + "py.test", + "--quiet", + f"--junitxml=unit_{session.python}_sponge_log.xml", + "--cov=google", + "--cov=tests/unit", + "--cov-append", + "--cov-config=.coveragerc", + "--cov-report=", + "--cov-fail-under=0", + os.path.join("tests", "mockserver_tests"), + *session.posargs, + ) + + def install_systemtest_dependencies(session, *constraints): # Use pre-release gRPC for system tests. # Exclude version 1.52.0rc1 which has a known issue.