Skip to content

Commit c8a320f

Browse files
committed
Add a test to check that we can't ask for m2m dirty fields if we have not enabled the m2m check mode
1 parent 143d67b commit c8a320f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tests/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,8 @@ def pre_save(instance, *args, **kwargs):
9191
instance.data_updated_on_presave = 'presave_value'
9292

9393
pre_save.connect(TestModelWithPreSaveSignal.pre_save, sender=TestModelWithPreSaveSignal)
94+
95+
96+
class TestModelWithoutM2MCheck(DirtyFieldsMixin, models.Model):
97+
characters = models.CharField(blank=True, max_length=80)
98+
ENABLE_M2M_CHECK = False

tests/test_m2m_fields.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

3-
from .models import TestModel, TestM2MModel, TestModelWithCustomPK, TestM2MModelWithCustomPKOnM2M
3+
from .models import TestModel, TestM2MModel, TestModelWithCustomPK, TestM2MModelWithCustomPKOnM2M, \
4+
TestModelWithoutM2MCheck
45

56

67
@pytest.mark.django_db
@@ -32,3 +33,11 @@ def test_m2m_check_with_custom_primary_key():
3233
# This line was triggering this error:
3334
# AttributeError: 'TestModelWithCustomPK' object has no attribute 'id'
3435
m2m_model.m2m_field.add(tm)
36+
37+
38+
@pytest.mark.django_db
39+
def test_m2m_disabled_does_not_allow_to_check_m2m_fields():
40+
tm = TestModelWithoutM2MCheck.objects.create()
41+
42+
with pytest.raises(Exception):
43+
assert tm.get_dirty_fields(check_m2m={'dummy': True})

0 commit comments

Comments
 (0)