#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,
not 'bytes'"
-------------------------------------+-------------------------------------
     Reporter:  Florian Mayer        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  migration, unicode,  |             Triage Stage:
  bytestring, TypeError              |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => needsinfo


Comment:

 Hi Florian.

 This doesn't make sense quite as it is.

 On Python 3 unprefixed string literals are just are ''unicode literals'',
 i.e. the `from __future__ import unicode_literals` doesn't do anything.

 > Under Python 3, e.g. its ​model manager name 'objects' will be
 interpreted as bytestring b'objects'.

 This is incorrect.

 {{{
 >>> 'objects'
 'objects'
 >>> 'objects'.encode('utf8')
 b'objects'
 >>>
 }}}

 On Python 3, it's only when you encode the string that you get bytes.

 So the question is How is this happening?

 > Can reproduce on Ubuntu 16.04 (Python 3.6.x Anaconda) and 14.04 (Python
 3.4.3).

 OK, so can you put this in a minimal project that reproduces the error?
 Then we've got something to look at.
 (In general, the `sites` app is part of Django's own test suite, so those
 migrations are run extensively without problem, on Python 3.)

 You said you're updating BOTH Django (from 1.11) and Python (from 2.7).
 One thought is to make sure you do the Python upgrade first. Rollback to
 1.11, upgrade to Python 3, run all migrations, and make sure everything is
 working. Then upgrade to Django 2.x. (This is just a sanity check. It
 doesn't explain the error you're seeing.)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29632#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.4089d894f07064ec0feab2cd3aff8966%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to