Skip to content

fix(migrations): use primary_key instead of deprecated pk in MigrationRecorder#2203

Open
mykolasolodukha wants to merge 1 commit into
tortoise:developfrom
mykolasolodukha:fix/recorder-pk-deprecation-warning
Open

fix(migrations): use primary_key instead of deprecated pk in MigrationRecorder#2203
mykolasolodukha wants to merge 1 commit into
tortoise:developfrom
mykolasolodukha:fix/recorder-pk-deprecation-warning

Conversation

@mykolasolodukha
Copy link
Copy Markdown
Contributor

Description

Build the MigrationRecorder bookkeeping model with primary_key=True instead of the deprecated pk=True, so applying migrations no longer emits tortoise's own pk DeprecationWarning.

Motivation and Context

tortoise/fields/base.py deprecated pk=/index= in favor of primary_key=/db_index=. But MigrationRecorder._make_model still used IntField(pk=True), so any project applying migrations tripped a DeprecationWarning raised from inside tortoise — with no way to silence it from their own code. This is a pure kwarg rename (identical behavior, no schema change). A codebase-wide sweep confirmed this was the only internal use of a deprecated field kwarg.

How Has This Been Tested?

Added a regression test in tests/migrations/test_recorder.py that instantiates MigrationRecorder with warning filters reset (to bypass the repo-wide filterwarnings ignore) and asserts no pk/index DeprecationWarning is emitted. Confirmed it fails before the rename and passes after. Full migrations suite green; ruff + mypy clean.

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.

The migration recorder built its bookkeeping model with the
deprecated `pk=True` field kwarg, so every project applying
migrations tripped tortoise's own `pk` DeprecationWarning — raised
from inside the library, with no way to silence it downstream.

Build the model with `primary_key=True` instead (identical behavior,
no schema change), and add a regression test that resets the warning
filters to confirm no `pk`/`index` deprecation is emitted.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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