Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support request and transaction tags #558

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

olavloite
Copy link
Contributor

Do not merge: Depends on googleapis/python-spanner#1262

Fixes #525

Adds support for setting transaction tags and request tags in dbapi.
This makes these options available to frameworks that depend on
dbapi, like SQLAlchemy and Django.

Towards #525
@olavloite olavloite added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 17, 2024
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. label Dec 17, 2024
@ahr9n
Copy link

ahr9n commented Dec 19, 2024

Thanks for your support!

BTW, this request_tag = self.execution_options.get("request_tag") means the request tag will be on connecting to spanner engines [so, it will be the same for all the transaction queries -- on transaction level], but it should be on executing queries [to be on query level], right?

transaction_tag = self.execution_options.get("transaction_tag") is making sense, since the whole transaction will belong to one connection.

@olavloite
Copy link
Contributor Author

@ahr9n

BTW, this request_tag = self.execution_options.get("request_tag") means the request tag will be on connecting to spanner engines [so, it will be the same for all the transaction queries -- on transaction level], but it should be on executing queries [to be on query level], right?

You can set execution_options on a lower level than the engine. E.g. it can also be set for specific queries like this:

with Session(engine.execution_options(read_only=True)) as session:
    # Execute two queries in a read-only transaction.
    session.scalars(
        select(Singer).execution_options(request_tag="my-tag-1")
    ).all()
    session.scalars(
        select(Singer).execution_options(request_tag="my-tag-2")
    ).all()

The request tag is then set on the cursor that is being used for the current query:

request_tag = self.execution_options.get("request_tag")
if request_tag:
    self.cursor.request_tag = request_tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. do not merge Indicates a pull request not ready for merge, due to either quality or timing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Spanner Request Options Tags
2 participants