Skip to content

Commit 67f5104

Browse files
authored
fix(spanner): restore implicit database_dialect reload in sync client (#1537)
**Problem** Following the introduction of AsyncIO support via CrossSync, code generation for the synchronous client caused a regression in Database.database_dialect. Previously, if the property was accessed and returned DATABASE_DIALECT_UNSPECIFIED, the client would implicitly make a blocking self.reload() to retrieve the dialect from the server. This was lost during the shift to CrossSync as properties cannot be asynchronous in the _async source of truth. **Solution** Restore the lazy-loading reload behavior via an environment check: __async/database.py_: Added if not CrossSync.is_async: guard directly into the database_dialect getter. This makes it un-reachable code in the async runtime (where blocking properties or un-awaited coroutines are frowned upon). _database.py_: The generator strips the CrossSync context into a standard synchronous self.reload() call, successfully maintaining strict backwards compatibility for all existing synchronous libraries.
1 parent 3909c04 commit 67f5104

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

packages/google-cloud-spanner/google/cloud/spanner_v1/_async/database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ def database_dialect(self):
410410
:rtype: :class:`google.cloud.spanner_admin_database_v1.types.DatabaseDialect`
411411
:returns: the dialect of the database
412412
"""
413+
if self._database_dialect == DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED:
414+
if not CrossSync.is_async:
415+
self.reload()
413416
return self._database_dialect
414417

415418
@property

packages/google-cloud-spanner/google/cloud/spanner_v1/database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ def database_dialect(self):
358358
359359
:rtype: :class:`google.cloud.spanner_admin_database_v1.types.DatabaseDialect`
360360
:returns: the dialect of the database"""
361+
if self._database_dialect == DatabaseDialect.DATABASE_DIALECT_UNSPECIFIED:
362+
self.reload()
361363
return self._database_dialect
362364

363365
@property

0 commit comments

Comments
 (0)