[Django] #29808: column checks inside "executor.py" is not case sensitive

16 views
Skip to first unread message

Django

unread,
Sep 30, 2018, 3:31:25 PM9/30/18
to django-...@googlegroups.com
#29808: column checks inside "executor.py" is not case sensitive
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: nobody
Type: | Status: new
Uncategorized |
Component: | Version: 2.1
Migrations | Keywords: migration fake-
Severity: Normal | initial case sensitive
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hello,
I'm using this guide https://datascience.blog.wzb.eu/2017/03/21/using-
django-with-an-existinglegacy-database for my studies with camelCasing
together with Django (yes, I'm still trying to keep the naming convention
we have inside our DB, also for the model's names)

Now, I'm really new to Django and I don't know if it's intended but this
part of code inside** "executor.py"**'''' is doing case sensitive
comparison to check if a column is already present in a database
{{{
column_names = [
column.name for column in
self.connection.introspection.get_table_description(self.connection.cursor(),
table)
]
if field.column not in column_names:
return False, project_state
}}}

so if my migration file contains something like this
{{{
migrations.AddField(
model_name='city',
name='countrycode',
field=models.ForeignKey(db_column='countryCode',
on_delete=django.db.models.deletion.CASCADE, to='my_DB.country'),
}}}

and I run **''python3 manage.py migrate --database my_DB --fake-
initial my_first_app''**

it fires an error saying that that table already exists
**''django.db.utils.OperationalError: (1050, "Table 'city' already
exists")''**

If I run **''python3 manage.py migrate --database my_DB --fake
my_first_app''** it correctly fakes my_first_app
The my_DB collation is case insenstive, while mysql is running with the
''" --lower-case-table-names=0"'' option

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

Django

unread,
Oct 1, 2018, 5:32:59 PM10/1/18
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation

-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Old description:

New description:

Hello,
I'm using this guide https://datascience.blog.wzb.eu/2017/03/21/using-
django-with-an-existinglegacy-database for my studies with camelCasing
together with Django (yes, I'm still trying to keep the naming convention
we have inside our DB, also for the model's names)

Now, I'm really new to Django and I don't know if it's intended but this

part of code inside `django/db/migrations/executor.py`' is doing case


sensitive comparison to check if a column is already present in a database
{{{
column_names = [
column.name for column in
self.connection.introspection.get_table_description(self.connection.cursor(),
table)
]
if field.column not in column_names:
return False, project_state
}}}

so if my migration file contains something like this
{{{
migrations.AddField(
model_name='city',
name='countrycode',
field=models.ForeignKey(db_column='countryCode',
on_delete=django.db.models.deletion.CASCADE, to='my_DB.country'),
}}}

and I run `python3 manage.py migrate --database my_DB --fake-initial
my_first_app`

it fires an error saying that that table already exists

`django.db.utils.OperationalError: (1050, "Table 'city' already exists")`

If I run `python3 manage.py migrate --database my_DB --fake my_first_app`
it correctly fakes my_first_app
The my_DB collation is case insensitive, while MySql is running with the
`' --lower-case-table-names=0`' option

--

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

Django

unread,
Nov 8, 2019, 7:26:46 PM11/8/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* status: new => assigned
* owner: nobody => Hasan Ramezani
* has_patch: 0 => 1


Comment:

Not sure about the solution.
PR just created for proposing the solution.

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

Django

unread,
Nov 14, 2019, 7:30:02 AM11/14/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* version: 2.1 => master
* needs_tests: 0 => 1


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

Django

unread,
Nov 14, 2019, 2:05:24 PM11/14/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


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

Django

unread,
Nov 14, 2019, 2:21:34 PM11/14/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


Comment:

Left a few comments for improvements.

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

Django

unread,
Nov 14, 2019, 5:55:55 PM11/14/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29808#comment:6>

Django

unread,
Nov 15, 2019, 3:37:14 AM11/15/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"530dd193f2a1c791c703f3f961e2296cbb316bf9" 530dd19]:
{{{
#!CommitTicketReference repository=""
revision="530dd193f2a1c791c703f3f961e2296cbb316bf9"
Fixed #29808 -- Fixed initial migration detection when identifiers are
case-insensitive.

Thanks Simon Charette for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29808#comment:8>

Django

unread,
Nov 15, 2019, 3:37:15 AM11/15/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"d0c86a1df4564c7c29d5112a73a32d369958880d" d0c86a1d]:
{{{
#!CommitTicketReference repository=""
revision="d0c86a1df4564c7c29d5112a73a32d369958880d"
Refs #29808 -- Optimized MigrationExecutor.detect_soft_applied().

Use set() for iterables used only for containment checks. Simplify
column checks O(n) instead of O(2n).

Thanks Simon Charette for an idea.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29808#comment:7>

Django

unread,
Nov 15, 2019, 3:06:28 PM11/15/19
to django-...@googlegroups.com
#29808: Applied migration detection may fail when using a case-insensitive
collation
-------------------------------------+-------------------------------------
Reporter: Elaci0 | Owner: Hasan
| Ramezani
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: migration fake- | Triage Stage: Accepted
initial case sensitive |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"4527d5db0f0a939439b9373f7a9a4eee3386afff" 4527d5db]:
{{{
#!CommitTicketReference repository=""
revision="4527d5db0f0a939439b9373f7a9a4eee3386afff"
Refs #29808 -- Fixed
MigrateTests.test_migrate_fake_initial_case_insensitive() crash on Oracle.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29808#comment:9>

Reply all
Reply to author
Forward
0 new messages