[Django] #30580: django.db.migrations.optimizer error in indention

8 views
Skip to first unread message

Django

unread,
Jun 19, 2019, 2:52:21 PM6/19/19
to django-...@googlegroups.com
#30580: django.db.migrations.optimizer error in indention
--------------------------------------+------------------------
Reporter: sijianlin | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
The command "makemigrations" yields operations in wrong order; base class
gets created later than ones depending on it. After tracing the issue we
are certain that the error comes from django.db.migrations.optimizer. In
the file optimizer.py method optimizer_inner,the "else" clause is clearly
misaligned. We currently disable the optimization to get the migration
operations in correct order.

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

Django

unread,
Jun 19, 2019, 5:42:08 PM6/19/19
to django-...@googlegroups.com
#30580: django.db.migrations.optimizer error in indention
----------------------------+--------------------------------------
Reporter: sijianlin | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Simon Charette):

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


Comment:

Hello there, thank you for your report.

It's possible the issue you are experiencing is legitimate but it's
unfortunately not possible for triagers to assert whether or not Django
is at fault because your report is missing detailed reproduction case.

Please reopen this ticket with a detailed step by step report of how to
reproduce the issue. It should contain the models used to the generate the
problematic migrations, the Django version you are using, and a sample of
the generated migration.

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

Django

unread,
Jul 22, 2019, 11:31:11 AM7/22/19
to django-...@googlegroups.com
#30580: django.db.migrations.optimizer error in indention
----------------------------+--------------------------------------
Reporter: sijianlin | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by sijianlin):

Please take a look at the the code /django/db/migrations/optimizer.py and
this is an apparent indention error- the last "else" is not matching with
the if clause.
Please assign to the author and get it fixed.
Thanks

{{{

def optimize_inner(self, operations, app_label=None):
"""Inner optimization loop."""
new_operations = []
for i, operation in enumerate(operations):
right = True # Should we reduce on the right or on the left.
# Compare it to each operation after it
for j, other in enumerate(operations[i + 1:]):
in_between = operations[i + 1:i + j + 1]
result = operation.reduce(other, app_label)
if isinstance(result, list):
if right:
new_operations.extend(in_between)
new_operations.extend(result)
elif all(op.reduce(other, app_label) is True for op in
in_between):
# Perform a left reduction if all of the in-
between
# operations can optimize through other.
new_operations.extend(result)
new_operations.extend(in_between)
else:
# Otherwise keep trying.
new_operations.append(operation)
break
new_operations.extend(operations[i + j + 2:])
return new_operations
elif not result:
# Can't perform a right reduction.
right = False
else:
new_operations.append(operation)
return new_operations
}}}

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

Django

unread,
Jul 22, 2019, 11:39:14 AM7/22/19
to django-...@googlegroups.com
#30580: django.db.migrations.optimizer error in indention
----------------------------+--------------------------------------
Reporter: sijianlin | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by Simon Charette):

I think you've misinterpreted the code; that's a `for else` clause that is
only executed if nothing `break` out of the loop.

https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-
statements-and-else-clauses-on-loops

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

Reply all
Reply to author
Forward
0 new messages