Code

Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#20207 closed Bug (fixed)

`ManyToManyField` with an unicode name fails to create an intermediary model.

Reported by: charettes Owned by: charettes
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I encountered the following error when porting an app codebase to support both python 2 and 3.

from __future__ import unicode_literals


class Teacher(models.Model):
    students_ = models.ManyToManyField(Student, name='students')  # Here the name is a unicode string because of the future import.

Raises:

TypeError: Error when calling the metaclass bases
    type() argument 1 must be string, not unicode

The culprit is this line. It should always be a str.

This was not introduced by the codebase port to Python 3 and thus it's not a release blocker.

Attaching a simple patch with tests in a few moments.

Attachments (1)

0001-Fixed-20207-Handle-ManyToManyField-with-a-unicode-na.patch (2.1 KB) - added by charettes 13 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 13 months ago by charettes

  • Has patch set

comment:2 Changed 13 months ago by claudep

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:3 Changed 13 months ago by aaugustin

It'd be nice to backport the fix to 1.5.

comment:4 Changed 13 months ago by Simon Charette <charette.s@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 216580e03499e035b93283df00fcc03b346fef7b:

Fixed #20207 -- Handle ManyToManyField with a unicode name correctly.

comment:5 Changed 13 months ago by Simon Charette <charette.s@…>

In d04e8f8c7869b79a6f848a94bd51ce71223c2df2:

[1.5.x] Fixed #20207 -- Handle ManyToManyField with a unicode name correctly.

Backport of 216580e034.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.