Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
18 changes: 18 additions & 0 deletions tests/migrations/test_recorder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from tortoise.backends.base.client import Capabilities
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tortoise/migrations/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down