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!

Back to Home
 Profile Picture
Profile Picture

About John Solly

I am a Senior Software Engineer with a focus on geospatial applications, based in the Columbus, OH metropolitan area. This blog is where I delve into the intricacies of GIS (Geographic Information Systems), offering deep dives into different components of the geospatial technology stack. For those who share a passion for GIS and its applications, you've found a spot to explore and learn.

Interested in collaborating or learning more about my work? Take a look at my portfolio for a showcase of my projects and expertise.

Comments

  • No comments yet.
Login to Comment