[Django] #25429: M2M migration is inconsistently case-sensitive

3 views
Skip to first unread message

Django

unread,
Sep 18, 2015, 1:58:58 PM9/18/15
to django-...@googlegroups.com
#25429: M2M migration is inconsistently case-sensitive
-------------------------+-------------------------------------------------
Reporter: staab | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
Migrations | Keywords: case sensitivity migrations
Severity: Normal | manytomany
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
When I rename a model and its uses to the same name with letters in
different cases (e.g., "TestThing" > "Testthing") in ManyToManyForeign
keys pointing to it, I get odd behavior in migrations. At times, the
migration gets stuck, and tries to run the same change multiple times
(since the relevant information is lowercase, it can't tell the difference
between the old state and the new state), and other times, I get an error
similar to the following:


{{{
Applying m2mtestcase.0003_auto_20150918_1747...Traceback (most recent call
last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/core/management/__init__.py", line 338, in
execute_from_command_line
utility.execute()
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/core/management/commands/migrate.py", line 222, in
handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/db/migrations/executor.py", line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake,
fake_initial=fake_initial)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/db/migrations/executor.py", line 148, in
apply_migration
state = migration.apply(state, schema_editor)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/db/migrations/migration.py", line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/db/migrations/operations/fields.py", line 201, in
database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/db/backends/base/schema.py", line 469, in
alter_field
return self._alter_many_to_many(model, old_field, new_field, strict)
File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
/site-packages/django/db/backends/sqlite3/schema.py", line 232, in
_alter_many_to_many
old_field.rel.through._meta.get_field(old_field.m2m_reverse_field_name()),
AttributeError: 'ManyToManyField' object has no attribute
'm2m_reverse_field_name'
}}}

Here's a shell script that you can run to create a django app and run
migrations that will cause this error (it assumes you're using
virtualenvwrapper and have access to GNU sed. Tweak it as necessary):


{{{
mkvirtualenv m2mcasesensitivity
pip install Django===1.8.4
django-admin startproject m2mcasesensitivity
cd m2mcasesensitivity
./manage.py startapp m2mtestcase
sleep 1 # Race condition?
sed -i 's/INSTALLED_APPS = (/INSTALLED_APPS = ("m2mtestcase",/'
m2mcasesensitivity/settings.py
echo "
from django.db import models

class FirstProblemModel(models.Model):
pass


class SecondProblemModel(models.Model):
first_things = models.ManyToManyField(FirstProblemModel)
" > m2mtestcase/models.py
./manage.py makemigrations
./manage.py migrate
sed -i 's/ProblemModel/problemmodel/g' m2mtestcase/models.py
./manage.py makemigrations
./manage.py migrate
sed -i 's/problemmodel/ProblemModel/g' m2mtestcase/models.py
./manage.py makemigrations
./manage.py migrate
}}}

{{{
To tear down:
deactivate
rmvirtualenv m2mcasesensitivity
cd ..
rm -rf m2mcasesensitivity
}}}

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

Django

unread,
Sep 18, 2015, 3:04:31 PM9/18/15
to django-...@googlegroups.com
#25429: M2M migration is inconsistently case-sensitive
-------------------------------------+-------------------------------------

Reporter: staab | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: case sensitivity | Triage Stage:
migrations manytomany | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

Seems to be similar to #23916. Do you think there's any reason to keep two
tickets open?

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

Django

unread,
Sep 21, 2015, 2:11:10 PM9/21/15
to django-...@googlegroups.com
#25429: M2M migration is inconsistently case-sensitive
-------------------------------------+-------------------------------------
Reporter: staab | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: duplicate

Keywords: case sensitivity | Triage Stage:
migrations manytomany | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

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


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

Reply all
Reply to author
Forward
0 new messages