Merge ~lvoytek/ubuntu/+source/python-django-modelcluster:fix-django4-compatibility into ubuntu/+source/python-django-modelcluster:ubuntu/devel

Proposed by Lena Voytek
Status: Merged
Approved by: git-ubuntu bot
Approved revision: not available
Merge reported by: Lena Voytek
Merged at revision: f9dd908618b8dfd40c7c7fc42ac72f0088feac33
Proposed branch: ~lvoytek/ubuntu/+source/python-django-modelcluster:fix-django4-compatibility
Merge into: ubuntu/+source/python-django-modelcluster:ubuntu/devel
Diff against target: 101 lines (+69/-1)
4 files modified
debian/changelog (+7/-0)
debian/control (+2/-1)
debian/patches/fix_test_suite_django_4plus.patch (+59/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
git-ubuntu bot Approve
Lucas Kanashiro (community) Approve
Canonical Server Reporter Pending
Review via email: mp+448282@code.launchpad.net

Description of the change

Fix compatibility with Django 4 by updating a test file

PPA building against 4.2: https://launchpad.net/~lvoytek/+archive/ubuntu/django-4-mantic
PPA building against 3.2 (currently in Ubuntu): https://launchpad.net/~lvoytek/+archive/ubuntu/django3-mantic

To post a comment you must log in.
Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote (last edit ):

Thanks for this MP Lena! Your patch indeed fixes the test failure, I checked the upstream code and it should also fail with Django 4:

https://github.com/wagtail/django-modelcluster/blame/main/tests/tests/test_cluster_form.py#L261

In the setup.py, there is no safeguard to avoid running it with Django 4:

https://github.com/wagtail/django-modelcluster/blob/main/setup.py#L21

So I think you can submit a PR already anticipating that. WDYT?

review: Needs Information
Revision history for this message
Lena Voytek (lvoytek) wrote :

I think that's reasonable. Though I looked at the open PRs upstream and actually found one that fixes the same issue I found in a similar way, https://github.com/wagtail/django-modelcluster/pull/174, albeit with a lot of extra changes.

Revision history for this message
Lena Voytek (lvoytek) wrote :

For us though, python-django-modelcluster will have to be compatible with 4.2 since Django 3.2 will no longer be available once the transition happens.

Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote :

Thanks for referring to this PR. I just tried to apply part of the changes in that PR (changes inside the test/ directory only) and they still work fine with Django 3.2 in the archive, and I assume it should work with Django 4.2 from your PPA as well. Could you please try that out?

I understand it was not merged upstream yet but the changes look reasonable to me. I think we should at least try to follow that, in this case we can use the proposed patch with some modifications. Moreover, the patch seems to also make sure the tests pass with Django master branch (>= 5.0), so this can avoid a similar issue when we perform the next transition. WDYT?

824a042... by Lena Voytek

* debian/patches/fix_test_suite_django_4plus.patch: Fix test suite to
  maintain compatibility with Django 4.2+ (LP: #2022089)

f9dd908... by Lena Voytek

changelog

Revision history for this message
Lena Voytek (lvoytek) wrote :

Sounds good to me, I turned my patch into a backport containing the test directory fixes

Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote :

Thanks Lena! That looks good to me now. I am sponsoring the upload for you:

Uploading python-django-modelcluster_6.0-2ubuntu1.dsc
Uploading python-django-modelcluster_6.0-2ubuntu1.debian.tar.xz
Uploading python-django-modelcluster_6.0-2ubuntu1_source.changes

review: Approve
Revision history for this message
git-ubuntu bot (git-ubuntu-bot) wrote :

Approvers: lucaskanashiro, lvoytek
Uploaders: lucaskanashiro
MP auto-approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index a1ea184..c7b9e6e 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+python-django-modelcluster (6.0-2ubuntu1) mantic; urgency=medium
7+
8+ * d/p/fix_test_suite_django_4plus.patch: Fix test suite to maintain
9+ compatibility with Django 4.2+ (LP: #2022089)
10+
11+ -- Lena Voytek <lena.voytek@canonical.com> Tue, 01 Aug 2023 15:52:22 -0700
12+
13 python-django-modelcluster (6.0-2) unstable; urgency=medium
14
15 * Team upload
16diff --git a/debian/control b/debian/control
17index 513e8bf..ebf67cb 100644
18--- a/debian/control
19+++ b/debian/control
20@@ -1,7 +1,8 @@
21 Source: python-django-modelcluster
22 Section: python
23 Priority: optional
24-Maintainer: Debian Python Team <team+python@tracker.debian.org>
25+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
26+XSBC-Original-Maintainer: Debian Python Team <team+python@tracker.debian.org>
27 Uploaders:
28 Michael Fladischer <fladi@debian.org>,
29 Build-Depends:
30diff --git a/debian/patches/fix_test_suite_django_4plus.patch b/debian/patches/fix_test_suite_django_4plus.patch
31new file mode 100644
32index 0000000..e941441
33--- /dev/null
34+++ b/debian/patches/fix_test_suite_django_4plus.patch
35@@ -0,0 +1,59 @@
36+Description: Fix build against Django 4.2+ by updating test suite
37+ When building against Django 4, the test_formfield_callback test fails due to
38+ an AssertionError. This is caused by the formfield_callback variable being
39+ missing from the BandFormWithFFC Meta subclass. In previous Django versions
40+ this was fine since formfield_callback exists in the BandFormWithFFC class
41+ itself. The issue is fixed by also adding the field to the Meta class in
42+ Django 4.2 and above. Meanwhile, for Django 5.0, an addition to test_tag is
43+ needed when checking html generation. In the new version, Django adds the
44+ aria-describedby attribute for accessibility. Adding this to the test html
45+ fixes the issue.
46+Author: irtazaakram <irtaza.akram@arbisoft.com>
47+Origin: backport, https://github.com/wagtail/django-modelcluster/pull/174/commits/4e0daeb0d5b3f7ab77c2edac4b7cc841fa2ed603
48+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/mantic/+source/python-django-modelcluster/+bug/2022089
49+Last-Update: 2023-08-02
50+---
51+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
52+--- a/tests/tests/test_cluster_form.py
53++++ b/tests/tests/test_cluster_form.py
54+@@ -272,6 +272,9 @@
55+ fields = ['name']
56+ formsets = ['members', 'albums']
57+
58++ if DJANGO_VERSION >= (4, 2):
59++ formfield_callback = formfield_for_dbfield
60++
61+ form = BandFormWithFFC()
62+ self.assertEqual(Textarea, type(form['name'].field.widget))
63+ self.assertEqual(Textarea, type(form.formsets['members'].forms[0]['name'].field.widget))
64+--- a/tests/tests/test_tag.py
65++++ b/tests/tests/test_tag.py
66+@@ -2,11 +2,12 @@
67+
68+ import unittest
69+
70++from django import VERSION as DJANGO_VERSION
71+ from django.test import TestCase, override_settings
72+ from taggit import VERSION as TAGGIT_VERSION
73+ from taggit.models import Tag
74+-from modelcluster.forms import ClusterForm
75+
76++from modelcluster.forms import ClusterForm
77+ from tests.models import NonClusterPlace, Place, TaggedPlace
78+
79+
80+@@ -148,7 +149,13 @@
81+ mission_burrito.tags.add('burrito', 'mexican')
82+ form = PlaceForm(instance=mission_burrito)
83+ form_html = form.as_p()
84+- self.assertInHTML('<input type="text" name="tags" value="burrito, mexican" id="id_tags">', form_html)
85++ html = '<input type="text" name="tags" value="burrito, mexican" id="id_tags">'
86++
87++ if DJANGO_VERSION >= (5, 0):
88++ # https://docs.djangoproject.com/en/dev/releases/5.0/#forms
89++ html = '<input type="text" name="tags" value="burrito, mexican" aria-describedby="id_tags_helptext" id="id_tags">'
90++
91++ self.assertInHTML(html, form_html)
92+
93+ @override_settings(TAGGIT_CASE_INSENSITIVE=True)
94+ def test_case_insensitive_tags(self):
95diff --git a/debian/patches/series b/debian/patches/series
96new file mode 100644
97index 0000000..ac95d12
98--- /dev/null
99+++ b/debian/patches/series
100@@ -0,0 +1 @@
101+fix_test_suite_django_4plus.patch

Subscribers

People subscribed via source and target branches

to all changes: