Skip to content

Fix transaction typing#2232

Open
vlakius wants to merge 3 commits into
tortoise:developfrom
vlakius:fix-transaction-typing
Open

Fix transaction typing#2232
vlakius wants to merge 3 commits into
tortoise:developfrom
vlakius:fix-transaction-typing

Conversation

@vlakius

@vlakius vlakius commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Changed type annotation in order to have the correct type annotation in

from tortoise.transactions import in_transaction

async def main():
    async with in_transaction() as conn: # <--- here

Description

Changed return type from generic T_conn to TransactionalDBClient

Motivation and Context

#2174

How Has This Been Tested?

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed-hq

codspeed-hq Bot commented Jun 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing vlakius:fix-transaction-typing (53329c6) with develop (9f42589)

Open in CodSpeed

Comment thread CHANGELOG.rst Outdated
- ``MigrationRecorder`` no longer emits tortoise's own ``pk`` field ``DeprecationWarning`` when applying migrations; it now builds its bookkeeping model with ``primary_key=True``. (#2203)
- ``QuerySet.count()`` now matches the limited query result for the LIMIT/OFFSET edge cases: it returns ``0`` (instead of a negative number) when ``offset()`` exceeds the total row count, and ``0`` (instead of the total) for ``limit(0)``. (#2208)
- Field declarations on models now resolve to their concrete type (e.g. ``CharField[str]``) in Pyright/Pylance instead of ``Field[Unknown]``; the ``Field.__new__`` type-check stub now returns ``Self``. (#2216)
- ``TransactionContext`` now returns a ``TransactionalDBClient`` instead of a raw database connection. This change gives the correct inferred type for the transaction context. (#2216)

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.

It is #2232 not #2216

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is #2232 not #2216

I corrected it, thanks

Updated the CHANGELOG with the correct PR number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants