Opened 9 years ago

Closed 8 years ago

#26385 closed Bug (wontfix)

Squashing migrations with Python 2.7 adds bytestring prefix to ManyToManyField 'to' values which fails to run on Python 3

Reported by: Brian May Owned by: nobody
Component: Migrations Version: 1.9
Severity: Normal Keywords: py2
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In attempting a work around for #26384 by squashing the commits, I found another problem:

E           AssertionError: ManyToManyField(b'spud.album') is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string 'self'

I believe the problem is that it used a byte value instead of a string.

        migrations.AddField(
            model_name='photo',
            name='albums',
            field=models.ManyToManyField(related_name='photos', through='spud.photo_album', to=b'spud.album'),
        ),

This works fine with Python 2.7 but not with Python 3.4.

The original before squashing was ok:

        migrations.AddField(
            model_name='photo',
            name='albums',
            field=models.ManyToManyField(related_name='photos', through='spud.photo_album', to='spud.album'),
            preserve_default=True,
        ),

Change History (5)

comment:1 by Brian May, 9 years ago

Forgot to mention, the squashed commits where created with Python 2.7

Version 0, edited 9 years ago by Brian May (next)

comment:2 by Brian May, 9 years ago

Looks like squashing the migration in Python3.4 creates a migration that will work with all versions of Python.

Curiously though with Python 2.7 it sets initial=True on the migration, but when squashed with Python3.4 it doesn't.

comment:3 by Tim Graham, 9 years ago

Summary: Squash migrations with Python 3.4 creates broken migrationsSquashing migrations with Python 2.7 adds bytestring prefix to ManyToManyField 'to' values which fails to run on Python 3
Triage Stage: UnreviewedAccepted

I can reproduce the issue but cannot track where the bytestring is coming from. A more minimal sample project may help but I think the issue isn't high priority since Python 2 support will be dropped soon.

comment:4 by Tim Graham, 8 years ago

Keywords: py2 added

comment:5 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

Closing given Python 2 support will be dropped in master in a couple weeks.

Note: See TracTickets for help on using tickets.
Back to Top