#22277: migrations: a migration that depends on itself causing
-------------------------------------+-------------------------------------
     Reporter:  Marcin Szamotulski   |                    Owner:  nobody
  <mszamot@…>                        |                   Status:  new
         Type:  Bug                  |                  Version:  master
    Component:  Migrations           |               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
 * component:  Uncategorized => Migrations
 * needs_tests:   => 0
 * needs_docs:   => 0
 * type:  Uncategorized => Bug


Old description:

> I have this list of migrations (migrations.loader line 196):
> for i in normal.items(): print(i)
> (('taggit', '0001_initial'), <Migration taggit.0001_initial>)
> (('accounts', '0003_image'), <Migration accounts.0003_image>)
> (('social_feel', '0008_post_editors'), <Migration
> social_feel.0008_post_editors>)
> (('social_feel', '0009_post_authors'), <Migration
> social_feel.0009_post_authors>)
> (('social_feel', '0006_postimagecomment'), <Migration
> social_feel.0006_postimagecomment>)
> (('accounts', '0001_initial'), <Migration accounts.0001_initial>)
> (('social_feel', '0010_postrevision_modified_by'), <Migration
> social_feel.0010_postrevision_modified_by>)
> (('social_feel', '0005_postimage'), <Migration
> social_feel.0005_postimage>)
> (('social_feel', '0003_postcomment'), <Migration
> social_feel.0003_postcomment>)
> (('social_feel', '0002_postauthor'), <Migration
> social_feel.0002_postauthor>)
> (('accounts', '0002_account'), <Migration accounts.0002_account>)
> (('social_feel', '0007_postrevision'), <Migration
> social_feel.0007_postrevision>)
> (('social_feel', '0001_initial'), <Migration social_feel.0001_initial>)
> (('social_feel', '0004_posteditor'), <Migration
> social_feel.0004_posteditor>)
>
> When the loops (django.db.migrations.loader 196):
>         for key, migration in normal.items():
>             for parent in migration.dependencies:
> are building dependencies for key = ('accounts', '0003_image')
> there are no dependencies yet in self.graph, and the parent of this key
> is set to ('accounts', '__first__').
> Then this parent is resolved by the line 230:
> parent = list(self.graph.root_nodes(parent[0]))[0]
>
> In pdb I can see that
> self.graph.root_nodes(parent[0]) returns:
> set([('accounts', '0003_image'), ('accounts', '0001_initial'),
> ('accounts', '0002_account')])
> also self.graph.dependencies returns:
> {}
>
> And then the parent (by the line 230) is set to ('accounts',
> '0003_image'), i.e. it is equal to key.
> At the end of this loop iteration this line is executed:
> self.graph.add_dependency(key, parent)
> which adds ('accounts', '0003_image') as a dependency of itself.
> Later on I can see this error:
> Traceback (most recent call last):
>   File "./manage.py", line 7, in <module>
>     execute_from_command_line(sys.argv)
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/core/management/__init__.py",
> line 427, in execute_from_command_line
>     utility.execute()
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/core/management/__init__.py",
> line 419, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/core/management/base.py",
> line 288, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/core/management/base.py",
> line 337, in execute
>     output = self.handle(*args, **options)
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/core/management/commands/makemigrations.py",
> line 80, in handle
>     loader.graph.project_state(),
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 138, in project_state
>     for migration in self.forwards_plan(node):
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 53, in forwards_plan
>     return self.dfs(node, lambda x: self.dependencies.get(x, set()))
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 119, in dfs
>     return _dfs(start, get_children, [])
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 111, in _dfs
>     results = _dfs(n, get_children, path) + results
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 111, in _dfs
>     results = _dfs(n, get_children, path) + results
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 111, in _dfs
>     results = _dfs(n, get_children, path) + results
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 111, in _dfs
>     results = _dfs(n, get_children, path) + results
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 111, in _dfs
>     results = _dfs(n, get_children, path) + results
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 111, in _dfs
>     results = _dfs(n, get_children, path) + results
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 111, in _dfs
>     results = _dfs(n, get_children, path) + results
>   File
> "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
> line 103, in _dfs
>     raise CircularDependencyError(path[path.index(start):] + [start])
> django.db.migrations.graph.CircularDependencyError: [('accounts',
> '0003_image'), ('accounts', '0003_image')]

New description:

 I have this list of migrations (migrations.loader line 196):
 {{{
 for i in normal.items(): print(i)
 (('taggit', '0001_initial'), <Migration taggit.0001_initial>)
 (('accounts', '0003_image'), <Migration accounts.0003_image>)
 (('social_feel', '0008_post_editors'), <Migration
 social_feel.0008_post_editors>)
 (('social_feel', '0009_post_authors'), <Migration
 social_feel.0009_post_authors>)
 (('social_feel', '0006_postimagecomment'), <Migration
 social_feel.0006_postimagecomment>)
 (('accounts', '0001_initial'), <Migration accounts.0001_initial>)
 (('social_feel', '0010_postrevision_modified_by'), <Migration
 social_feel.0010_postrevision_modified_by>)
 (('social_feel', '0005_postimage'), <Migration
 social_feel.0005_postimage>)
 (('social_feel', '0003_postcomment'), <Migration
 social_feel.0003_postcomment>)
 (('social_feel', '0002_postauthor'), <Migration
 social_feel.0002_postauthor>)
 (('accounts', '0002_account'), <Migration accounts.0002_account>)
 (('social_feel', '0007_postrevision'), <Migration
 social_feel.0007_postrevision>)
 (('social_feel', '0001_initial'), <Migration social_feel.0001_initial>)
 (('social_feel', '0004_posteditor'), <Migration
 social_feel.0004_posteditor>)
 }}}

 When the loops (django.db.migrations.loader 196):
 {{{
         for key, migration in normal.items():
             for parent in migration.dependencies:
 }}}
 are building dependencies for `key = ('accounts', '0003_image')`
 there are no dependencies yet in `self.graph`, and the parent of this key
 is set to `('accounts', '__first__')`.
 Then this parent is resolved by the line 230:
 {{{
 parent = list(self.graph.root_nodes(parent[0]))[0]
 }}}
 In pdb I can see that
 {{{
 self.graph.root_nodes(parent[0]) returns:
 set([('accounts', '0003_image'), ('accounts', '0001_initial'),
 ('accounts', '0002_account')])
 also `self.graph.dependencies` returns:
 {}
 }}}

 And then the parent (by the line 230) is set to `('accounts',
 '0003_image')`, i.e. it is equal to key.
 At the end of this loop iteration this line is executed:
 `self.graph.add_dependency(key, parent)`
 which adds ('accounts', '0003_image') as a dependency of itself.
 Later on I can see this error:
 {{{
 Traceback (most recent call last):
   File "./manage.py", line 7, in <module>
     execute_from_command_line(sys.argv)
   File
 
"/home/coot/webapps/social_feel/venv/src/django/django/core/management/__init__.py",
 line 427, in execute_from_command_line
     utility.execute()
   File
 
"/home/coot/webapps/social_feel/venv/src/django/django/core/management/__init__.py",
 line 419, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File
 
"/home/coot/webapps/social_feel/venv/src/django/django/core/management/base.py",
 line 288, in run_from_argv
     self.execute(*args, **options.__dict__)
   File
 
"/home/coot/webapps/social_feel/venv/src/django/django/core/management/base.py",
 line 337, in execute
     output = self.handle(*args, **options)
   File
 
"/home/coot/webapps/social_feel/venv/src/django/django/core/management/commands/makemigrations.py",
 line 80, in handle
     loader.graph.project_state(),
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 138, in project_state
     for migration in self.forwards_plan(node):
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 53, in forwards_plan
     return self.dfs(node, lambda x: self.dependencies.get(x, set()))
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 119, in dfs
     return _dfs(start, get_children, [])
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 111, in _dfs
     results = _dfs(n, get_children, path) + results
   File
 "/home/coot/webapps/social_feel/venv/src/django/django/db/migrations/graph.py",
 line 103, in _dfs
     raise CircularDependencyError(path[path.index(start):] + [start])
 django.db.migrations.graph.CircularDependencyError: [('accounts',
 '0003_image'), ('accounts', '0003_image')]
 }}}

--

Comment:

 Added some formatting for readability. In the future, please use preview,
 thanks!

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22277#comment:1>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/096.c6568085769ba989864599b42548a312%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to