Add warning to upgrade contrib.sites.migrations.0001 when upgrading from Python 2.x to 3.x
See original GitHub issueDescription
I’d like to suggest to include a note/warning/docs section on a unicode/bystestring tripwire users will encounter when upgrading a cookiecutter-django project which was generated under Python 2.x / Django 1.x to Python 3.x / Django 2.x.
Use case:
- A Django project was generated using cookiecutter-django in a Python 2.7 / Django 1.9 environment (latest Django at the time).
- Django migrations generate the occasional explicit bytestrings, e.g. at model manager names (
b'objects'
). - Django project gets upgraded to Python 3.x / Django>2.0 (drops Python 2.x support).
- Python 3 strings expect to be unicode, Django will trip over bytestrings - this breaks migrations with explicit
b'bytestrings'
. - Debugging Django leads the user towards django.contrib.sites - easy to confuse django’s core module with the one pasted by cookiecutter-django!
- Confusion, troubleshooting and resolution see https://code.djangoproject.com/ticket/29632
As an artefact of using cookiecutter-django under Python 2, and c-d’s inclusion of a project-side contrib.auth.sites, the stray bytestring in the project-side contrib.auth.sites migration 0001 escaped my attention longer than it should have. Note this bytestring is generated when running cookiecutter-django under Python 2.x – it’s not in c-d’s template for this migration!
Could some kind of reminder be included? c-d does a great job including rationale e.g. [https://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django why is there a django-contrib-sites].
Rationale
It would help users upgrading their Python and Django environment when they get stuck at this spurious bug.
Use case(s) / visualization(s)
Possibly a separate top level entry in the docs “Upgrading a cookiecutter-django project from Python 2.x to 3.x / Django 1.x to 2.x” and a fat warning in the autogenerated settings linking to that section in the docs. Happy to send PR if appropriate!
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (3 by maintainers)
Top GitHub Comments
I’m closing this old issue. It’s been more than 3 years that we dropped support for Python 2, and documentaing this migration is no longer in scope of the project. This issue in itself does a good enough job for it.
One thing that helped me in the past which isn’t mentioned in this thread yet is the excellent
pyupgrade
library.Sorry, I never got around to send a PR, and thanks for all the feedback. Hope this issue is enough to get others unstuck!