fix(migrations): use primary_key instead of deprecated pk in MigrationRecorder#2203
Open
mykolasolodukha wants to merge 1 commit into
Open
Conversation
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>
waketzheng
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Build the
MigrationRecorderbookkeeping model withprimary_key=Trueinstead of the deprecatedpk=True, so applying migrations no longer emits tortoise's ownpkDeprecationWarning.Motivation and Context
tortoise/fields/base.pydeprecatedpk=/index=in favor ofprimary_key=/db_index=. ButMigrationRecorder._make_modelstill usedIntField(pk=True), so any project applying migrations tripped aDeprecationWarningraised 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.pythat instantiatesMigrationRecorderwith warning filters reset (to bypass the repo-widefilterwarningsignore) and asserts nopk/indexDeprecationWarningis emitted. Confirmed it fails before the rename and passes after. Full migrations suite green;ruff+mypyclean.Checklist: