Django puts out a fantastic doc on upgrading to the latest version. I am using Django 3.2.7 and the latest is  3.2.13. I follow a process instead of blindly upgrading to upgrade from Bootstrap 4 to 5.

Review Release Notes

I read the release notes for versions between my current version and the latest. For me that’s 3.2.8->3.2.9->3.2.10->3.2.11>3.2.12>3.2.13. I see nothing stand out that would break my app. I’m fortunate this is not a large version jump (like 3.x to 4.x) which comes with depreciations and breaking changes. There's currently an open issue to do this major version upgrade on blogthedata.com

Resolve depreciation warnings and run unit tests

According to the docs:

Before upgrading, it’s a good idea to resolve any deprecation warnings raised by your project while using your current version of Django. Fixing these warnings before upgrading ensures that you’re informed about areas of the code that need altering.

In Python, deprecation warnings are silenced by default. You must turn them on using the -Wa Python command line option or the PYTHONWARNINGS environment variable. For example, to show warnings while running tests:

When I ran the tests, everything looked wonderful except for depreciation warnings within the django-admin-honeypot module. I don’t worry because the error targets Django 4.0, not 3.x

/code/blogthedata/django_project/venv/lib/python3.9/site-packages/admin_honeypot/admin.py:31: RemovedInDjango40Warning: django.utils.translation.ugettext_lazy() is deprecated in favor of django.utils.translation.gettext_lazy().
  get_path.short_description = _('URL')

A quick note on Python dependencies...there's a chance some Python modules will break in the latest Django version that won't show up in the depreciation warnings. Unfortunately, I don’t know how to test dependencies premetively. According to this SO thread, you basically upgrade and see what happens with the stack traces.

Backup Dependencies

The app running on my local machine in a virtualenv. To take a snapshot of dependencies, I run pip freeze to save them to a requirements.txt file. This file can be used to re-create the virtualenv if things go sideways.

pip freeze > requirements_5_4_22.txt

Perform the Upgrade in the Dev Environment

pip install Django==3.2.13

I re-ran my unit tests and everything passed!

Perform the Upgrade in Prod

First I commit the requirements file to source control. Then I use it to upgrade Django in production.

Everything went smoothly! Prod is now on the latest 3.x Django version!

Comments

Back to Home
John Solly Profile Picture
John Solly Profile Picture

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 New Light Technologies (NLT), 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!