diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b111c9525..7e7f6da4c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -21,6 +21,7 @@ Added Fixed ^^^^^ - ``MigrationRecorder`` now uses parameterized queries; fixes MariaDB/MySQL rejecting ISO-8601 ``applied_at`` values. (#2132) +- ``MigrationRecorder`` no longer emits tortoise's own ``pk`` field ``DeprecationWarning`` when applying migrations; it now builds its bookkeeping model with ``primary_key=True``. 1.1.7 ----- diff --git a/tests/migrations/test_recorder.py b/tests/migrations/test_recorder.py index d56498e3a..3b76829b2 100644 --- a/tests/migrations/test_recorder.py +++ b/tests/migrations/test_recorder.py @@ -1,3 +1,5 @@ +import warnings + import pytest from tortoise.backends.base.client import Capabilities @@ -126,6 +128,22 @@ async def test_recorder_sqlite_placeholders() -> None: assert '"name" = ?' in delete_query +def test_recorder_model_emits_no_field_deprecation_warnings() -> None: + """Regression: the migration recorder must not trip tortoise's own + ``pk``/``index`` field deprecation warnings. It builds its bookkeeping + model internally, so downstream projects can't silence them. + """ + with warnings.catch_warnings(record=True) as caught: + # Reset filters so the repo-wide ``ignore:`pk` deprecation`` filter in + # pyproject.toml doesn't mask a regression here. + warnings.simplefilter("always") + MigrationRecorder(FakeConnection("sqlite")) + + messages = [str(w.message) for w in caught if issubclass(w.category, DeprecationWarning)] + assert not any("`pk` is deprecated" in m for m in messages), messages + assert not any("`index` is deprecated" in m for m in messages), messages + + @pytest.mark.asyncio async def test_recorder_oracle_placeholders() -> None: connection = FakeConnection("oracle") diff --git a/tortoise/migrations/recorder.py b/tortoise/migrations/recorder.py index 82420059e..e2877da0b 100644 --- a/tortoise/migrations/recorder.py +++ b/tortoise/migrations/recorder.py @@ -35,7 +35,7 @@ def _placeholder(self, pos: int) -> str: def _make_model(self, table_name: str) -> type[Model]: class MigrationRecord(Model): - id = fields.IntField(pk=True) + id = fields.IntField(primary_key=True) app = fields.CharField(max_length=255) name = fields.CharField(max_length=255) applied_at = fields.DatetimeField()