Skip to content

Commit 6248f36

Browse files
authored
Merge branch 'main' into django-5.2
2 parents 7ce73f2 + a2543df commit 6248f36

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

mailing/tests/test_forms.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for mailing app forms."""
22
from django.test import TestCase
3+
from django.contrib.contenttypes.models import ContentType
34

45
from mailing.tests.forms import TestBaseEmailTemplateForm
56

@@ -13,6 +14,10 @@ def setUp(self):
1314
"internal_name": "notification 01",
1415
}
1516

17+
def tearDown(self):
18+
super().tearDown()
19+
ContentType.objects.clear_cache()
20+
1621
def test_validate_required_fields(self):
1722
required = set(self.data)
1823
form = TestBaseEmailTemplateForm(data={})

pydotorg/settings/local.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@
6363
REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'] += (
6464
'rest_framework.renderers.BrowsableAPIRenderer',
6565
)
66+
67+
BAKER_CUSTOM_CLASS = "pydotorg.tests.baker.PolymorphicAwareBaker"

pydotorg/tests/baker.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from polymorphic.models import PolymorphicModel
2+
from model_bakery import baker
3+
4+
5+
class PolymorphicAwareBaker(baker.Baker):
6+
"""
7+
Our custom model baker ignores the polymorphic_ctype field on all polymorphic
8+
models - this allows the base class to set it correctly.
9+
10+
See https://github.com/python/pythondotorg/issues/2567
11+
"""
12+
13+
def get_fields(self):
14+
fields = super().get_fields()
15+
if issubclass(self.model, PolymorphicModel):
16+
fields = {field for field in fields if field.name != "polymorphic_ctype"}
17+
return fields

0 commit comments

Comments
 (0)