I’m in the process of porting a Python 2.7/Django 1.8 project to more recent versions of both, namely Django 2.2 and Python >= 3.7. It’s proving to be a bit more challenging than initially thought, especially dealing with the project’s external dependencies (both widely used packages such as django-cms or crispy forms, and also external packages developed in-house which haven’t been ported either).
Now I have a functioning environment which I’ve upgraded to use pytest and vagrant, but I am facing a dilemma: should I first upgrade Python or Django ?
- Django 1.8 is compatible with Python 3 up to 3.5.
- Django 1.11 is compatible with Python 3 up to 3.7
- Django 2.0 drops support for Python 2 and works with 3.7
- Django 2.2 still works with Python 3.5
So, should I
- first upgrade to Django 1.11, keeping python 2.7, then upgrade python to 3.7, and then move to Django 2.2 ?
- first upgrade to 3.5, then upgrade Django to 2.2, then python to 3.8 ?
Also, would I be better off upgrading Django one major version at a time or skip directly from 1.8 to the highest possible version ?
Any help, comments or further questions greatly appreciated !
Do these upgrades, releasing them one at a time:
- Django 1.8 -> 1.9
- Django 1.9 -> 1.10
- Django 1.10 -> 1.11
- Python 2.7 -> 3.7
- Django 1.11 -> 2.0
- etc. up to Django 3.0
It’s not really safe to upgrade more than one Django feature version at a time. You can maybe do two or three if you carefully read the release notes and check for all warnings, but it’s better to keep the changes small. It might take a bit of coordination with third party packages. Django has documentation on upgrading: https://docs.djangoproject.com/en/3.0/howto/upgrade-version/
For Python 2 to 3 my blog post may be of use: https://adamj.eu/tech/2016/08/24/upgrading-yplan-to-python-3-with-zero-downtime/ . This is focussed heavily on zero downtime so if you can afford to be a bit looser you can combine some steps. I’d also add running pyupgrade to the list these days: https://github.com/asottile/pyupgrade/
If you have any ability to space the upgrades out you’ll be able to narrow down any bugs they reveal or cause much better. Django is pretty backwards compatible but you’ll still find significant changes that will be hard to discover if you have low test coverage.
Hope that helps!
N.B. I have a chapter on upgrading both Django and Python in my book Speed Up Your Django Tests. It has some checklists for general processes of doing these upgrades, though not much on Python 2->3.
Wow, someone was reading my mind. I just running into the same kind of issue – django 1.9.x based project, not as bad dependency-wise, but still a major chunk of work. Thanks to both of you folks.
I wish both of you welcome to the Django forum!
Thanks so much Adam, this sounds like a really good plan, and the links are incredibly useful !
This topic is just the conversation I am looking for!
I’ve come into a large project stuck at Django 1.5. The goal is to move this 10 year old project to python3 and a current version of Django 3.x. There is also a desire to do a code audit and dump cruft.
- I’m wondering if it would make sense to copy/port code into a fresh install of Django 1.11 then do Python 2.7 -> 3.7 and finally follow the minor version upgrades to the target version? similar to what adamchainz suggested.
- Or copy/port django code to Django 3.0 and also change python from 2 to 3 at the same time?
My gut is saying option 1. which is more inline with admanchainz suggestion, but my gut has been known to get things wrong
Any discussion on this topic would be a huge help, Thank you in advance!