#28350: UnboundLocalError in RenameField.state_forwards
-----------------------------------------+------------------------
               Reporter:  Daniel Hahler  |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Migrations     |        Version:  1.11
               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              |
-----------------------------------------+------------------------
 I've just seen the following error:

 > UnboundLocalError: local variable 'field' referenced before assignment

 {{{
 Traceback (most recent call last):
   File "manage.py", line 8, in <module>
     execute_from_command_line(sys.argv)
   File "…/Vcs/django/django/core/management/__init__.py", line 363, in
 execute_from_command_line
     utility.execute()
   File "…/Vcs/django/django/core/management/__init__.py", line 355, in
 execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "…/Vcs/django/django/core/management/base.py", line 283, in
 run_from_argv
     self.execute(*args, **cmd_options)
   File "…/Vcs/django/django/core/management/base.py", line 330, in execute
     output = self.handle(*args, **options)
   File "…/Vcs/django/django/core/management/commands/migrate.py", line 92,
 in handle
     conflicts = executor.loader.detect_conflicts()
   File "…/Vcs/django/django/db/migrations/executor.py", line 81, in
 _create_project_state
     migration.mutate_state(state, preserve=False)
   File "…/Vcs/django/django/db/migrations/migration.py", line 92, in
 mutate_state
     operation.state_forwards(self.app_label, new_state)
   File "…/Vcs/django/django/db/migrations/operations/fields.py", line 289,
 in state_forwards
     delay = not field.is_relation
 UnboundLocalError: local variable 'field' referenced before assignment
 }}}

 Looking at the code shows that `field` might not be assigned in case
 `new_name` is not found:
 
https://github.com/django/django/blob/a6756195c1a11eee10c16c96fe95d52e22e1d9ba/django/db/migrations/operations/fields.py#L284-L289

 I've seen this while manually squashing migrations (messing around with
 the `replaces` in the first three new migrations), so this is likely to be
 constructed / caused by doing something unexpected there, but I think it
 should still get handled in a better way, i.e. by throwing a proper error
 with information/context about the RenameField operation.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.6231f847fdb30d138f9f4bc851db0e89%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to