Opened 11 years ago

Last modified 11 years ago

#22277 closed Bug

migrations: a migration that depends on itself causing — at Version 1

Reported by: Marcin Szamotulski <mszamot@…> Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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')]

Change History (1)

comment:1 by Tim Graham, 11 years ago

Component: UncategorizedMigrations
Description: modified (diff)
Type: UncategorizedBug

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

Note: See TracTickets for help on using tickets.
Back to Top