<p>Troggle is built on top of the django framework. In 2019 we had let ourselves get rather behind in keeping up to date with the django version and this held us back from upgrading the operating system - which we needed to do. Troggle uses several community-contributed django plugins and each of these had their own version dependencies. We also got caught up with out of date and deprecated python language features.
<p>A ridiculous amount of work was required to get to a situation where troggle was running on relatively recent and nearly security-in-date versions of python, django, plugins and linux by Summer 2020. We don't want that to happen again.
<h4>Why this is difficult</h4>
<p>When django upgrades to a new version things break across the entire django package, including things which we don't conciously use but are 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 requires 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.
<h4>Major, minor and releases</h4>
<p>Django release 1.11.29 is major-version 1, minor-version 11, and patch-release 29. 1.11 is the "feature release".
<p>Things <em>will break</em> between <ahref="https://docs.djangoproject.com/en/3.0/internals/release-process/">django minor-versions</a> (feature releases) which come out every 8 months.
<li>Django has a mature and reliable release programme: <ahref="http://docs.djangoproject.com/en/3.0/releases/">https://docs.djangoproject.com/en/3.0/releases/</a>
<li>Django pre-announces which features will be deprecated: <ahref="https://docs.djangoproject.com/en/3.0/internals/deprecation/">docs.djangoproject.com/en/internals/deprecation/</a>
<p>But the contributed plugins have no such management process and releases are rather random, e.g. for django-registration there are two sources of current information:<br/>
<p>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.
<p>Every extra plugin increases the "vulnerability surface" of troggle with respect to django upgrade problems so only install a new plugin if it is really, really necessary. For example, when django-staticfiles broke during one upgrade we discovered that we could use flatfiles as a workaround, so we are not planning on reinstalling staticfiles ever again.
<p>[ However django-extensions looks like it could be useful explicitly to help us through the upgrade process:
<ahref="https://pypi.org/project/django-extensions/">pypi.org/project/django-extensions/</a> (only available for django 2.2 and later). ]
<p>Well we <ahref="trog2030.html">might not use django indefinitely</a>, but unlike many frameworks the necessary functions are separately replaceable. So this gives us an evolution path.
<p>The stack is: database, request/response (GET/POST http),
<ahref="https://docs.djangoproject.com/en/1.11/topics/http/urls/">URL mapping/dispatch</a> (declarative and bidrectional), and <ahref="https://docs.djangoproject.com/en/3.0/topics/templates/">templates</a> (data to HTML). See the <ahref="https://docs.djangoproject.com/en/3.0/misc/design-philosophies/">django design philosophy</a>. Note that having a URL dispatcher that supports <ahref="https://docs.djangoproject.com/en/1.11/topics/http/urls#s-reverse-resolution-of-urls">reverse resolution</a> is important: it is a key reason why we need a framework and not just a mess of javascript. We have nearly 100 URL patterns.
<li>Use <ahref="https://docs.python.org/3/library/venv.html">pip venv</a> to set up 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 venv <var>t37</var> start it up like this:<br/>
<li>Use the <em>highest release number</em> when upgrading between minor-versions of django. <br/>So we went from 1.8.19 to 1.9.13 to 1.10.8 to 1.11.29 . Next will be 2.0.13, then 2.1.15 and then 2.2.15 .
<li>Use our test suite (and if you see errors, run it with <var>-v 3</var>)<br/>
<var>troggle$ python manage.py test [-v 3]</var><br>
<li>Read all the release notes for <em>all</em> the intermediate releases. So from 1.1.29 we will read <ahref="https://docs.djangoproject.com/en/3.0/releases/">14 sets of notes</a>: for <ahref="https://docs.djangoproject.com/en/3.0/releases/2.0/">2.0</a>, 2.0.1, 2.0.2... up to 2.0.13 .
</ol>
<p>The individual releases within a minor version don't break anything but do fix bugs. So if you are on 1.10.x there is no point in getting 1.11.1 to work and you should go straight to 1.11.29 (29 is the highest release number in minor version 1.11).
<p><var>--deploy</var> gives django warnings about security issues in your settings as well as django deprecation warnings.<br>
<var>-Wall</var> 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 (in fact 1.11.29 is incompatible with python 3.8 too but we didn't get a warning about that).
<h3>The upgrade process</h3>
<ol>
<li>ensure that you have the exact version of python installed on your machine as is live for troggle on the server, e.g. do <var>$ sudo apt install python3.7.5</var>.
<li>create a venv using the version of python to be used.
<li>do <ahref="/repositories/troggle/.git/tree/README.txt">a clean install</a> of django and troggle using pip.
<li>check the versions of plugins using <var>pip list -o</a>
<li>open two terminal windows:
<br>- one will be used for installations and tests.
<br>- the other one will be used for <var>python manage.py runserver 0.0.0.0:8000 -v 3</var> (or whatever portnumber you like)
<li>rename the most recent localsettingsXXX.py to fit your local system and make it symlink to localsettings.py
<li>edit your localsettingsXXX.py to use sqlite with a file <var>troggle.sqlite</var>
<li>edit your localsettingsXXX.py to set a password for user "expo" (or just use default "nnn:gggggg")
<li>start the runserver in the other terminal window and open a web browser to http://localhost:8000 and check important pages which we don't have tests for (yet):
<li>Use the error dump tracebacks to find and correct the python code. [Running the server in a debugger would help: please add those instructioons for that to this page.]
<li>run the script <var>./pre-run.sh</var> to clean up everything before the next round of tests.