CUCC Expedition Handbook

Upgrading Django for Troggle

Why this used to be difficult

Before Django 3.0, whenever Django was upgraded to a new version things broke across the entire django package, including things which we did't conciously use but which were internal dependencies within Django. These were 'the way to do it' when troggle was first written for Django 0.7 in 2006. So upgrading troggle to a new Django version required not just a broad beadth of knowledge across troggle, but also across the entire breadth of Django itself. And the error messages are sometimes very unhelpful. This is no longer the case and the Django organisation has a very clear "non-breaking" policy between LTS releases.

Now read Django and Troggle if you haven't already.

Note that Django 3.2 is out of support since April 2024.

Django versions and update schedule

Release Series Latest Release End of support End of security fixes
6.1 August 2026 April 2027 December 2027
6.0 December 2025 August 2026 April 2027
5.2 LTS April 2025 December 2025 April 2028
5.1 5.1.3 April 2025 December 2025
5.0 5.0.9 August 7, 2024 April 2025
4.2 LTS 4.2.16 December 4, 2023 April 2026
4.1 4.1.13 April 5, 2023 December 1, 2023
4.0 4.0.10 August 3, 2022 April 1, 2023
3.2 LTS 3.2.8 December 2021 April 2024
3.1 3.1.13 April 2021 December 2021
3.0 3.0.14 August 2020 April 2021
2.2 LTS 2.2.20 December 2019 April 2022

Major, minor and releases

Django release 4.2.16 is major-version 4, minor-version 2, and patch-release 16. 4.2 is the "feature release" and patch releases within each feature release are not meant to break anything. They are just to fix bugs.

Things will break between feature releases which come out every 8 months. We plan on upgrading troggle on the server whenever we upgrade the server operating system, which we do only every 2-3 years between Debian LTS releases.

You will come to rely extensively on the release notes and versions documentation which is maintained by django.

You will also need to read the django guide to upgrading to newer versions.

Django plugins ("apps")

Documentation for the plugins is highly variable and plugin projects, being run by volunteers, can just die unexpectedly. For the django-registration plugin there are two sources of current information:
Docs: django-registration 3.1
PyPi: django-registration 3.1

but only one of these (PyPi) gives release history data - which is what you need if you get behind with the django upgrades.

Django plugin documentation cannot be relied upon to tell you which version of django they require. They will complain when you run them if your version of django is too old though. Some experimentation is required.

[ However django-extensions looks like it could be useful explicitly to help us through the upgrade process: pypi.org/project/django-extensions/ (only available for django 2.2 and later). ]

Troggle software development

Upgrading the version of django used by troggle can be a serious programming job. It is not just a matter of editing a few config files. You will need a full troggle software development environment set up on your machine including, most definitely, the capability of running the troggle test suite. See how to set up a troggle software development laptop. Note particularly that you will find sqlite database browser software very helpful and that you will need to know git.

Important Tricks

There are six critical tricks that make everything much, much easier:

  1. Use a virtual python environment within which you can easily and quickly change the specific releases of python, django, django's dependencies and django plugins. With a previously created envornment .venv start it up like this:
    cd ~/expo/troggle
    source .venv/bin/activate
    python --version
    django-admin
    python manage.py
    python manage.py check -v 3
    django-admin check
    python manage.py test -v 3 --traceback
  2. Use the highest release number when upgrading between minor-versions of django.
    So we went from 1.8.19 to 1.9.13 to 1.10.8 to 1.11.29 to 2.0.13 to 2.1.15 then 2.2.19 (variously patched at .20, .24, .25) and then 3.2.10 when we upgraded debian 10 (buster) to 11 (bullseye).
  3. Use the django 'check' maintenance system at the most verbose setting at each release
    troggle$ python manage.py check -v 3 --deploy
    troggle$ python -Wall manage.py check
  4. Use our test suite (and if you see errors, run it with -v 3)
    troggle$ python manage.py test [-v 3] [--parallel auto]
    The --parallel option runs the tests in parallel on your machine which is much faster.
  5. Read all the release notes for all the intermediate releases. So from 1.1.29 we read 14 sets of notes: for 2.0, 2.0.1, 2.0.2... up to 2.0.13 .
  6. Seriously learn how to use the traceback webpage produced by django when a page crashes. There is a full record of every variable value hidden in there.
  7. You will be doing a lot of local testing just on your development machine. The default is to use the webserver built into Django: python manage.py runserver 0.0.0.0:8000 -v 3. Alternatively you can install and use gunicorn: gunicorn --reload -w 9 -b :8000 wsgi. the '-w' flag is for the number of worker threads and should be 2n+1 where n is the number of cpu cores on your machine.

Deprecation warnings and python versions

The individual releases within a minor version don't break anything but do fix bugs. So if you are on 4.1.x there is no point in getting 4.2.1 to work and you should go straight to the latest available on your machine of the 4.2 feature release, e.g. 4.2.5 on debian 13.

check --deploy gives django warnings about security issues in your settings as well as django deprecation warnings.
-Wall is a standard python option and gives warnings of deprecated python features used by django and all the current plugins. So it tells us that django 1.11.29 is using a deprecated python language feature which will be removed from the language in python 3.9 . Python version compatibilities are documented at the top of each y.x.0 release note. From Django 4.2 it requires python 3.8, but python 3.11 is recommended.

The upgrade process

Django migrations - prior reading

Even if you have made no changes to the data model, and thus the database scheme is unchanged, you still have to run the Django migration software between different Django Feature Releases, e.g. between 3.1.x and 3.2.y .

Even if you have not made any changes, Django itself may have made substantial changes to its admin data model and so the database structure needs to be migrated to the new structure - even though it is an empty database since we recreate it all every time we do a data import.

Now might also be a good idea to get familiar with using a database browser (see configuring a troggle laptop) and use it with the example project described in the Primer article: which you should run through on your own machine.

Running troggle before and after a Django migration

  1. ensure that you have the exact same version of python installed on your machine as is live for troggle on the server, so check the line
    requires-python = ">=3.11,<3.12"
    in the file server.toml.
  2. Copy server.toml on top of pyprojectr.toml and synchronise the environment: uv sync.
  3. check the versions of plugins using uv tree
    (troggle) philip@Mohawk:~/expo/troggle$ uv tree --all-groups
    Resolved 11 packages in 0.54ms
    troggle-server v2024.12.1
    ├── beautifulsoup4 v4.11.2 (group: server)
    │   └── soupsieve v2.6
    ├── coverage v7.6.9 (group: server)
    ├── django v3.2.19 (group: server)
    │   ├── asgiref v3.8.1
    │   ├── pytz v2024.2
    │   └── sqlparse v0.5.3
    ├── piexif v1.1.3 (group: server)
    ├── pillow v9.4.0 (group: server)
    └── unidecode v1.3.6 (group: server)
  4. open two terminal windows:
  5. run a script ./pre-push.sh to make a sanitised copy (no passwords) of localsettings.py as localsettingsXXX.py before every commit
  6. edit your localsettings.py to use sqlite with a file troggle.sqlite
  7. edit your localsettings.py to set a password for users "expo" & "expoadmin" (or just use default "nnn:gggggg")
  8. testing:
  9. Use the error dump tracebacks to find and correct the python code. [Running the server in a debugger would help: please add those instructions for that to this page.]
  10. run the script ./pre-run.sh to clean up everything before the next round of tests.

Django database dependencies

On the expo server we run MariaDB as the database which has its own dependencies. In particular under debian buster we had to use MariaDB v1.3.10 which was the latest version supported by Debian buster:

mysqlclient==1.3.10
which is technically incompatible with Django 2.2 which requires 1.3.13. This incompatibility is a policy choice by the Django team. Wookey ran the Django system tests with 1.3.10 (April 2020) and it worked fine. Django just didn't support it because they couldn't spare the effort to test it.

To run Django's system test suite:

This is only necessary if we hit a policy-imposed incompatibility, as we did with mysqlclient==1.3.10 . We have only ever had to do this once.

Follow the instructions in the "Unit tests" section installed locally at docs/internals/contributing/writing-code/unit-tests.txt, published online at docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/ This involves running git clone on the django source repo to download the tests. We hope we never have to do this again but in case we get incomprehensible bugs in future, we should be prepared to do so.

Current upgrade status is documented: here.


Go on to: Troggle architecture
Return to: Django and Troggle
Return to: Troggle intro
Return to: Troggle programmers' guide
Go to: ⚒ Troggle development laptopTroggle development WSL laptop

Troggle index: Index of all troggle documents