My friend Justin created an issue in my repo for migrating to Django 4.0. I couldn’t because a dependency, django-admin-honeypot, and HTMX did not work on 4.0. I made the leap after HTMX officially started advertising 4.0 support.
With this PR, I’ve migrated blogthedata.com to Django 4.0.5.
The upgrade
Startup Error
I followed my upgrade document and ran into my first issue; The app wouldn’t start! There was an error in the console:
RuntimeError: populate() isn’t reentrant
It’s an unhelpful Django error often due to a misconfigured dependency in settings.py. Someone mentioned in this SO thread that a one-line change in django/apps/
registry.py
surfaces the error.
Sure enough, the error was coming from a module I incorporated in the past.
Could not import ugettext_lazy
The Django 4.0 upgrade doc states that Django 4.0 removes this import.
I found an open issue in the django-admin-honeypot repo, but no one has actioned it for three months. My options were:
1 - Drop the package
2 - Patch it myself
3 - Find a replacement.
There are similar repos (1, 2), but these packages aren’t well maintained either. Additionally, re-work was required to change modules. I chose to eliminate the dependency. Although the functionality is interesting, it hasn’t caught any login attempts (who hacks a personal blog?).
Migration error
The app failed again but from a migration error. Migration, 0006_change_content_field_to_richtextuploading.py, imports the old django-ckeditor package I used when first implementing CKEditor.
I saw this ticket in the official Django repo, where a commenter suggests migration squashing. Squash migrations reduce the number of migrations by ‘squashing’ them into one file.
$ python3 manage.py squashmigrations blog 0006
Will squash the following migrations:
- 0001_initial
- 0002_add_likes
- 0003_add_views_to_Post
- 0004_add_slug_field
- 0005_add_images_to_post
- 0006_change_content_field_to_richtextuploading
Do you wish to proceed? [yN]
Typed ‘Y’ and hit enter
Created new squashed migration /Users/johnsolly/Documents/code/blogthedata/django_project/blog/migrations/0001_squashed_0006_change_content_field_to_richtextuploading.py
You should commit this migration but leave the old ones in place;
the new migration will be used for new installs. Once you are sure
all instances of the codebase have applied the migrations you squashed,
you can delete them.
I followed the instructions, and everything started working again!
Conclusion
I ran into two errors during the upgrade from Django 3.2.14 to 4.0.5. The first was a third-party dependency not supported on 4.0. A second issue was a migration error from a removed dependency. The missing import was resolved by eliminating a dependency. The second issue was addressed by squashing migrations.
I am excited to now use Django 4.0!
Comments
- No comments yet.
John Solly
Hi, I'm John, a Software Engineer with a decade of experience building, deploying, and maintaining cloud-native geospatial solutions. I currently serve as a senior software engineer at HazardHub (A Guidewire Offering), where I work on a variety of infrastructure and application development projects.
Throughout my career, I've built applications on platforms like Esri and Mapbox while also leveraging open-source GIS technologies such as OpenLayers, GeoServer, and GDAL. This blog is where I share useful articles with the GeoDev community. Check out my portfolio to see my latest work!
0