[Django] #21308: DatabaseError running tests with MySQL & utf8mb4 charset

19 views
Skip to first unread message

Django

unread,
Oct 22, 2013, 8:01:29 PM10/22/13
to django-...@googlegroups.com
#21308: DatabaseError running tests with MySQL & utf8mb4 charset
----------------------------------------+--------------------
Reporter: Greg Barker <fletch@…> | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------+--------------------
Character set and collation set to utf8mb4:
{{{
$ cat /etc/mysql/my.cnf | grep utf8
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
}}}

Create a new site
{{{
$ virtualenv test-env
$ cd test-env
$ source ./bin/activate
(temp-test) $ pip install django
(temp-test) $ pip install mysql-python
(temp-test) $ django-admin.py startproject mysite
}}}

Update settings.py to use MySQL and create your database

Then run the tests, hit the error
{{{
$ python mysite/manage.py test
Creating test database for alias 'default'...
DatabaseError: (1071, 'Specified key was too long; max key length is 767
bytes')
}}}

MySQL query log reveals it fails on this statement:
{{{
CREATE TABLE `auth_customuser` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`password` varchar(128) NOT NULL,
`last_login` datetime NOT NULL,
`email` varchar(255) NOT NULL UNIQUE,
`is_active` bool NOT NULL,
`is_admin` bool NOT NULL,
`date_of_birth` date NOT NULL
)
}}}

Which originates from custom_user.py in django.contrib.auth.tests
{{{
class CustomUser(AbstractBaseUser):
email = models.EmailField(verbose_name='email address',
max_length=255, unique=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
date_of_birth = models.DateField()
}}}

I think it should be like the User class, which does not specify the
max_length, so it defaults the value to 75.

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

Django

unread,
Oct 22, 2013, 8:19:07 PM10/22/13
to django-...@googlegroups.com
#21308: DatabaseError running tests with MySQL & utf8mb4 charset
-------------------------------------+-------------------------------------
Reporter: Greg Barker | Owner: nobody
<fletch@…> | Status: new
Type: Bug | Version: 1.5
Component: contrib.auth | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Seems like a duplicate (or at least related) to #21196. I don't see how
the proposed change would fix the issue - have you tested it?

--
Ticket URL: <https://code.djangoproject.com/ticket/21308#comment:1>

Django

unread,
Oct 22, 2013, 8:44:14 PM10/22/13
to django-...@googlegroups.com
#21308: DatabaseError running tests with MySQL & utf8mb4 charset
-------------------------------------+-------------------------------------
Reporter: Greg Barker | Owner: nobody
<fletch@…> | Status: new
Type: Bug | Version: 1.5
Component: contrib.auth | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Greg Barker <fletch@…>):

Replying to [comment:1 timo]:


> Seems like a duplicate (or at least related) to #21196. I don't see how
the proposed change would fix the issue - have you tested it?

Oops, didn't see your reply on the mailing list before I submitted this
ticket.

After removing max_length from those two EmailFields in custom_user.py,
I'm able to run the tests successfully:

{{{
$ python mysite/manage.py test
Creating test database for alias 'default'...

..................................................................................................................................................s......................................................................................................................................x.......................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 481 tests in 12.454s

OK (skipped=1, expected failures=1)
Destroying test database for alias 'default'...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21308#comment:2>

Django

unread,
Oct 22, 2013, 9:53:52 PM10/22/13
to django-...@googlegroups.com
#21308: DatabaseError running tests with MySQL & utf8mb4 charset
-------------------------------------+-------------------------------------
Reporter: Greg Barker | Owner: nobody
<fletch@…> | Status: new
Type: Bug | Version: 1.5
Component: contrib.auth | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by ramiro):

From http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html

''' Tip

To save space with UTF-8, use VARCHAR instead of CHAR. Otherwise, MySQL
must reserve three (or four) bytes for each character in a CHAR CHARACTER
SET utf8 (or utf8mb4) column because that is the maximum possible
length.'''

Django CharFields map to SQL CHAR. That would mean that the maximum
working max_length value in this particular case should be 191.

--
Ticket URL: <https://code.djangoproject.com/ticket/21308#comment:3>

Django

unread,
Oct 22, 2013, 10:01:21 PM10/22/13
to django-...@googlegroups.com
#21308: DatabaseError running tests with MySQL & utf8mb4 charset
-------------------------------------+-------------------------------------
Reporter: Greg Barker | Owner: nobody
<fletch@…> | Status: new
Type: Bug | Version: 1.5
Component: contrib.auth | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by ramiro):

I'd say this ticket and #21196 are duplicates of #18392.

--
Ticket URL: <https://code.djangoproject.com/ticket/21308#comment:4>

Django

unread,
Oct 30, 2013, 12:14:44 PM10/30/13
to django-...@googlegroups.com
#21308: DatabaseError running tests with MySQL & utf8mb4 charset
-------------------------------------+-------------------------------------
Reporter: Greg Barker | Owner: nobody
<fletch@…> | Status: closed
Type: Bug | Version: 1.5
Component: contrib.auth | Resolution: duplicate

Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

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


Comment:

Ok, closing this as a duplicate of #18392. Made a note of this there.

--
Ticket URL: <https://code.djangoproject.com/ticket/21308#comment:5>

Reply all
Reply to author
Forward
0 new messages