Upgrade to Django 3.2 and bump base image to v3.10 #329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves TLT-4240 and TLT-4260.
Depends on https://github.com/Harvard-University-iCommons/django-icommons-common/pull/216.
Summary
This PR:
v3.10
of the build and base images.django-sslserver
withdjango-extensions
since the former is incompatible with Django 3.x.debug_toolbar
fromlocal.py
(for reasons explained below).Resolving incompatibilities with
django-angular
and Django 3.2After some research, it seems that django-angular does not officially support Django 3.2 (more specifically, any version of Django >3.0). According to an issue on the project's GitHub repo (which I came upon after running into the listed error during the upgrade), this appears to be because the primary project maintainer (and creator?) has since developed a different library (django-formset) to serve a similar purpose and no longer maintains the django-angular project.
Since the project's no longer maintained, there was an initial goal to find a way to remove uses of this library from the application. While this initially seemed promising, it was later discovered that CAAT's AngularJS frontend relies heavily on the library's middleware component for reversing URLs (e.g.
var URL_LISTS = djangoUrl.reverse('mailing_list:api_lists');
).So, for now at least, we still need this library to keep things functioning. The next step was to determine if there's a way to continue using this library despite its incompatibility with Django 3.2. Through trial and error, two primary errors were addressed:
django-angular
raised an error on startup when attempting to render a form by request fromdebug_toolbar.middleware.DebugToolbarMiddleware
(see the issue mentioned earlier: module 'django.forms.forms' has no attribute 'BoundField' jrief/django-angular#357). Stopping use ofdebug_toolbar
resolved the error.FORM_RENDERER = 'djng.forms.renderers.DjangoAngularBootstrap3Templates'
frombase.py
fixed the issue. Note that removing this setting bypassesdjango-angular
's form renderer (which is not compatible with Django 3.2) in favor of Django's default form renderer (note that overriding Django's form renderer is a listed step on the library's installation guide).The two fixes above (removing
debug_toolbar
to resolve issues when running locally and removing theFORM_RENDERER
override frombase.py
to resolve the failed rendering of a "Create New Job" form) ultimately resolved all errors.Note that there was some experimentation to update the forked
django-angular
library itself to determine how easy it would be to resolve some of the Django incompatibilities. Long story short, barring additional time and research, the only clear fix here is to bypass the library's incompatible form renderer via the method above.Forking the repo
On a separate note, It was determined in a meeting with Chris that forking the repo would be a good way to ensure we always have a local copy of the code (lest something happens to the original repo), so this particular branch is pointed to a newly-tagged version of the forked repo (
v2.3
). This tag points to the merge commit forrelease/2.3
(commit in original source repo here: Harvard-University-iCommons/django-angular@b825b80).Oddly enough, the
django-angular
repo did not receive a2.3
tag (the latest tagged version in the source repo is2.2.4
: https://github.com/jrief/django-angular/tags), yet PyPI provides a2.3
version of the library (https://pypi.org/project/django-angular/), presumably containing the changes merged in by therelease/2.3
branch. I'm not sure of the reason for this discrepancy (maybe the maintainer just got lazy near the end?), but it's an interesting thing to note.Testing
This branch is currently running on QA. Testing was performed via manual use of each of the project's apps (Search Courses, Search People, etc.).
Example sub-account in QA for testing: https://canvas.qa.tlt.harvard.edu/accounts/11/external_tools/3.