question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add warning to upgrade contrib.sites.migrations.0001 when upgrading from Python 2.x to 3.x

See original GitHub issue

Description

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:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
browniebrokecommented, Sep 9, 2020

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.

0reactions
florianmcommented, Sep 10, 2020

Sorry, I never got around to send a PR, and thanks for all the feedback. Hope this issue is enough to get others unstuck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

After migrating a Django project from Python 2 to 3, db ...
#29632: After migrating a Django project from Python 2 to 3, db migration of django.contrib.sites fails with "TypeError: attribute name must be string,...
Read more >
Porting Python 2 Code to Python 3 — Python 3.11.1 ...
Once your code works under Python 3, you should update the classifiers in your setup.py to contain Programming Language :: Python :: 3...
Read more >
After migrating a Django project generated with cookiecutter ...
x to 3.x, db migration of (cookiecutter-django generated, not Django module) django.contrib.sites fails with "TypeError: attribute name must be string ...
Read more >
Python 2.7 to 3.X Migration Guide - STX Next
This guide will show you how to upgrade to Python 3 quickly, easily, and cost-effectively. We'll assume you already have the latest Python...
Read more >
ValueError: The field accounts.VerifiedEmail.social ... - GitHub
Steps to reproduce Upgrade from Weblate 2.10 to 2.11 Adapt configuration changes from settings_example.py Run migration Actual behaviour python .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found