Skip to content

Commit 0d9bc8b

Browse files
archTortugaxclaude
andcommitted
Apply CodeRabbit review fixes
- serializers/base.py: fix "constitency" typo → "consistency" - utils.py: remove redundant setdefault() on line 72; remove unnecessary list() wrapping in _diff_by_content(); add idempotency note to patch_transaction_test_case docstring - fixture.py: wrap diff() body in try/finally so dump_path is always unlinked, even when a diff is found - tox.ini: bump docs env Django from >=4.2,<5.0 to >=5.2,<6.0 - settings_postgresql.py: update ENGINE to django.db.backends.postgresql - ci.yml: bump codecov/codecov-action@v4 → @v6 - CHANGELOG: split 0.9.7 entry into one item per line - test_fixture.py: add inline comment noting expected fixture content - docs/index.rst: add automodule directives for serializers.json and apps - pyproject.toml: exclude test packages from wheel discovery Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ab81b3a commit 0d9bc8b

10 files changed

Lines changed: 39 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ jobs:
7171
DB_PASSWORD: dbdiff
7272
PGPASSWORD: dbdiff
7373
- name: Upload coverage
74-
uses: codecov/codecov-action@v4
74+
uses: codecov/codecov-action@v6
7575
with:
7676
fail_ci_if_error: false

CHANGELOG

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
0.9.7 Fix always-False diff condition (temp file leak + assertNoDiff TypeError on exact match); add Python 3.10-3.14 and Django 4.2/5.2/6.0 support; drop Python 3.8/3.9 and Django EOL versions; migrate to pyproject.toml; modernize CI (checkout@v4, setup-python@v5, codecov-action); add automated PyPI release workflow
1+
0.9.7 Fix always-False diff condition (temp file leak + assertNoDiff TypeError on exact match)
2+
Use ignore_pk in ContentTypeTestCase for Django 6.0 content-type ordering stability
3+
Add Python 3.10-3.14 and Django 4.2/5.2/6.0; drop EOL Python 3.8/3.9 and Django 4.0/4.1
4+
Migrate to pyproject.toml; modernize CI (checkout@v4, setup-python@v5, codecov-action@v6)
25

36
0.9.6 Add support for Python 3.12
47

dbdiff/fixture.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,25 @@ def diff(self, exclude=None, ignore_pk=None):
108108
exclude_final = copy.copy(self.exclude)
109109
exclude_final.update(exclude or {})
110110

111-
with os.fdopen(fh, 'w') as f:
112-
self.dump(f)
111+
try:
112+
with os.fdopen(fh, 'w') as f:
113+
self.dump(f)
113114

114-
with open(self.path, 'r') as e, open(dump_path, 'r') as r:
115-
expected, result = json.load(e), json.load(r)
115+
with open(self.path, 'r') as e, open(dump_path, 'r') as r:
116+
expected, result = json.load(e), json.load(r)
116117

117-
if ignore_pk is None:
118-
ignore_pk = self.ignore_pk
118+
if ignore_pk is None:
119+
ignore_pk = self.ignore_pk
119120

120-
unexpected, missing, different = diff(
121-
get_tree(expected, exclude_final),
122-
get_tree(result, exclude_final),
123-
ignore_pk=ignore_pk,
124-
)
121+
unexpected, missing, different = diff(
122+
get_tree(expected, exclude_final),
123+
get_tree(result, exclude_final),
124+
ignore_pk=ignore_pk,
125+
)
126+
finally:
127+
os.unlink(dump_path)
125128

126129
if not unexpected and not missing and not different:
127-
os.unlink(dump_path)
128130
return None
129131

130132
return unexpected, missing, different

dbdiff/serializers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def remove_microseconds(cls, data):
4949

5050
@classmethod
5151
def normalize_decimals(cls, data):
52-
"""Strip trailing zeros for constitency.
52+
"""Strip trailing zeros for consistency.
5353
5454
In addition, dbdiff serialization forces Decimal normalization, because
5555
trailing zeros could happen in inconsistent ways.

dbdiff/tests/project/settings_postgresql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
DATABASES = {
66
'default': {
7-
'ENGINE': 'django.db.backends.postgresql_psycopg2',
7+
'ENGINE': 'django.db.backends.postgresql',
88
'HOST': os.environ.get('DB_HOST', ''),
99
'NAME': os.environ.get('DB_NAME', 'dbdiff_test'),
1010
'USER': os.environ.get('DB_USER', 'postgres'),

dbdiff/tests/test_fixture.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ def test_diff_exact_match_returns_none(self):
2828
# Regression: the always-False `not diff` (imported function) bug
2929
# caused diff() to never return None, leaking temp files and breaking
3030
# assertNoDiff() with a TypeError on exact matches.
31+
# Fixture contains: [{"model": "auth.group", "pk": 1, "fields": {"name": "initial_name"}}]
3132
Group.objects.create(id=1, name='initial_name')
3233
assert self.fixture.diff() is None

dbdiff/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def diff(expected, result, ignore_pk=False): # noqa: C901
6969
if expected_fields == result_fields:
7070
continue
7171

72-
different.setdefault(model, {})
7372
different.setdefault(model, {}).setdefault(pk, {})
7473

7574
for expected_field, expected_value in expected_fields.items():
@@ -94,7 +93,7 @@ def _diff_by_content(expected, result): # noqa: C901
9493
result_list = list(result.get(model, {}).items())
9594
matched_result_indices = set()
9695

97-
for exp_pk, exp_fields in list(expected_list):
96+
for exp_pk, exp_fields in expected_list:
9897
found = False
9998
for i, (res_pk, res_fields) in enumerate(result_list):
10099
if i in matched_result_indices:
@@ -154,7 +153,14 @@ def get_models_tables(models):
154153

155154

156155
def patch_transaction_test_case():
157-
"""Monkeypatch TransactionTestCase._reset_sequences to support SQLite."""
156+
"""Monkeypatch TransactionTestCase._reset_sequences to support SQLite.
157+
158+
Safe to call once, from AppConfig.ready(). Calling it a second time would
159+
wrap the already-patched classmethod again; the inner _needs_explicit_cls
160+
check would then see a classmethod and call _original(db_name), passing
161+
db_name correctly, so double-patching doesn't break anything — but callers
162+
should avoid it anyway.
163+
"""
158164
import inspect
159165

160166
from django.test.testcases import TransactionTestCase

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ API Reference
1414

1515
.. automodule:: dbdiff.test
1616
:members:
17+
18+
.. automodule:: dbdiff.serializers.json
19+
:members:
20+
21+
.. automodule:: dbdiff.apps
22+
:members:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ include-package-data = true
4444

4545
[tool.setuptools.packages.find]
4646
where = ["."]
47+
exclude = ["dbdiff.tests*", "tests*", "tests.*"]
4748

4849
[tool.ruff]
4950
line-length = 79

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ commands =
7070
sphinx-build -W -b html docs docs/_build/html
7171
deps =
7272
sphinx
73-
Django>=4.2,<5.0
73+
Django>=5.2,<6.0
7474
setenv =
7575
DJANGO_SETTINGS_MODULE=dbdiff.tests.project.settings_sqlite

0 commit comments

Comments
 (0)