feat: implement native asyncio support via Cross-Sync by sinhasubham · Pull Request #1509 · googleapis/python-spanner · GitHub
Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

feat: implement native asyncio support via Cross-Sync#1509

Merged
sinhasubham merged 13 commits into
mainfrom
async_support_2
Mar 23, 2026
Merged

feat: implement native asyncio support via Cross-Sync#1509
sinhasubham merged 13 commits into
mainfrom
async_support_2

Conversation

@sinhasubham

@sinhasubham sinhasubham commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Description: Native Asyncio Support
This PR introduces comprehensive, native asyncio support to the google-cloud-spanner library. It transitions the library into a "Cross-Sync" architecture, where the asynchronous implementation serves as the source of truth, and the synchronous implementation is automatically kept in parity.

Key Technical Changes
Core Library Porting

  • Asynchronous API: Introduced AsyncClient, AsyncInstance, and AsyncDatabase classes.
  • Session Management: Completely refactored pool.py to support asyncio. Replaced threading.Lock and queue.Queue with their asyncio counterparts via the CrossSync abstraction.
  • Transactions & Snapshots: Native async implementation of run_in_transaction, including robust retry logic for Aborted exceptions and proper lock management.

Verification & Testing
9 New System Tests: Created a dedicated async system test suite (tests/system/_async/) covering:
Rich data types (Timestamp, JSON, Protobuf, etc.)
Transaction retry loops
Partitioned DML operations
Session pool lifecycle
100% Pass Rate: All new async tests and existing sync tests pass reliably against the Spanner Emulator.
Mock Server Updates: Added 40+ mock server tests to verify specific async behaviors like result-set iteration and error handling.

@product-auto-label product-auto-label Bot added size: xl Pull request size is extra large. api: spanner Issues related to the googleapis/python-spanner API. labels Mar 2, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant architectural change with the new Cross-Sync mechanism for generating synchronous code from an asynchronous source. The implementation of the code generation and the new async components is well-structured. However, I've identified a critical issue in an async transport interceptor where a missing await will likely cause runtime errors. Additionally, there are opportunities for improvement by refactoring duplicated code in the AST transformers, enhancing the robustness of AST checks, and correcting some documentation typos and inaccuracies. Addressing these points will further strengthen this excellent contribution towards native asyncio support.

Comment thread google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py Outdated
Comment thread google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py Outdated
Comment thread .cross_sync/README.md Outdated
Comment thread .cross_sync/README.md Outdated
Comment thread .cross_sync/README.md Outdated
Comment thread .cross_sync/generate.py Outdated
Comment thread .cross_sync/transformers.py Outdated
Comment thread google/cloud/aio/_cross_sync/_decorators.py Outdated
@chalmerlowe

Copy link
Copy Markdown
Contributor

📢 Migration Notice: 📢 This library is moving to the google-cloud-python monorepo soon.

We kept this PR open due to recent activity. We would like to finalize this PR so it can be merged if it is critical.

If we don't hear from the PR author, we will close this PR in the next few days. The PR can then be re-opened in the monorepo once the migration is complete and work can continue there.

@sinhasubham sinhasubham force-pushed the async_support_2 branch 2 times, most recently from d953dc8 to e7b576a Compare March 3, 2026 15:13
@sinhasubham

Copy link
Copy Markdown
Contributor Author

📢 Migration Notice: 📢 This library is moving to the google-cloud-python monorepo soon.

We kept this PR open due to recent activity. We would like to finalize this PR so it can be merged if it is critical.

If we don't hear from the PR author, we will close this PR in the next few days. The PR can then be re-opened in the monorepo once the migration is complete and work can continue there.

Hi,
This is an ongoing project for asyncIO support and is planned to be closed by 31/03. Are you okay with this timeline for monorepo migration?

@sinhasubham sinhasubham marked this pull request as ready for review March 10, 2026 11:10
@sinhasubham sinhasubham requested review from a team as code owners March 10, 2026 11:10
@sinhasubham sinhasubham force-pushed the async_support_2 branch 2 times, most recently from 5f5c4c7 to d857aa3 Compare March 13, 2026 14:42

@bhatt4982 bhatt4982 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM...

Comment thread noxfile.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove "--quite" mode...

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

Labels

api: spanner Issues related to the googleapis/python-spanner API. size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants