Opened 6 years ago

Closed 6 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 Changed 6 years ago by Brian May

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

Last edited 6 years ago by Brian May (previous) (diff)

comment:2 Changed 6 years ago by Brian May

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 Changed 6 years ago by Tim Graham

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 Changed 6 years ago by Tim Graham

Keywords: py2 added

comment:5 Changed 6 years ago by Tim Graham

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