Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wagtailcore.pagerevision model name resolution error in migrations #643

Merged
merged 1 commit into from
Nov 4, 2022

Conversation

laymonage
Copy link
Member

@laymonage laymonage commented Oct 25, 2022

Fixes #642.

Prior work, for reference: #613, #616, #630

@laymonage laymonage force-pushed the fix-chicken-and-egg branch from 547d843 to 5ad5774 Compare October 25, 2022 13:55
@codecov-commenter
Copy link

Codecov Report

Base: 91.78% // Head: 91.78% // No change to project coverage 👍

Coverage data is based on head (5ad5774) compared to base (fb4db60).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #643   +/-   ##
=======================================
  Coverage   91.78%   91.78%           
=======================================
  Files          46       46           
  Lines        3980     3980           
  Branches      603      603           
=======================================
  Hits         3653     3653           
  Misses        194      194           
  Partials      133      133           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@nickmoreton nickmoreton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here have fixed the following error while running migrations.

Traceback
Applying wagtail_localize.0001_initial...Traceback (most recent call last):
  File "/app/manage.py", line 13, in <module>
    execute_from_command_line(sys.argv)
  File "/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/venv/lib/python3.9/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File "/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/venv/lib/python3.9/site-packages/django/core/management/commands/test.py", line 55, in handle
    failures = test_runner.run_tests(test_labels)
  File "/venv/lib/python3.9/site-packages/django/test/runner.py", line 725, in run_tests
    old_config = self.setup_databases(aliases=databases)
  File "/venv/lib/python3.9/site-packages/django/test/runner.py", line 643, in setup_databases
    return _setup_databases(
  File "/venv/lib/python3.9/site-packages/django/test/utils.py", line 179, in setup_databases
    connection.creation.create_test_db(
  File "/venv/lib/python3.9/site-packages/django/db/backends/base/creation.py", line 74, in create_test_db
    call_command(
  File "/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 181, in call_command
    return command.execute(*args, **defaults)
  File "/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/venv/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/venv/lib/python3.9/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/venv/lib/python3.9/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/venv/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/venv/lib/python3.9/site-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/venv/lib/python3.9/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
    schema_editor.create_model(model)
  File "/venv/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 343, in create_model
    sql, params = self.table_sql(model)
  File "/venv/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 162, in table_sql
    definition, extra_params = self.column_sql(model, field)
  File "/venv/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 215, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "/venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 1004, in db_parameters
    return {"type": self.db_type(connection), "check": self.db_check(connection)}
  File "/venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 1001, in db_type
    return self.target_field.rel_db_type(connection=connection)
  File "/venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 897, in target_field
    return self.foreign_related_fields[0]
  File "/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 644, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
  File "/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 632, in related_fields
    return self.resolve_related_fields()
  File "/venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 936, in resolve_related_fields
    related_fields = super().resolve_related_fields()
  File "/venv/lib/python3.9/site-packages/django/db/models/fields/related.py", line 615, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'wagtailcore.pagerevision' cannot be resolved

I am upgrading from Wagtail v3 to v4 and have used laymonage:fix-chicken-and-egg

I thought it might help.

@zerolab
Copy link
Collaborator

zerolab commented Nov 2, 2022

Thanks for testing on a real project, @nickmoreton
On my list for Friday to review and get a new release out

@nickmoreton
Copy link
Contributor

Thanks for testing on a real project

No problem @zerolab

In the end I needed to use the init method on the problem migrations to add in the wagtail migration as a dependency but only if that migration had not been run (a fresh development site). By checking with MigrationRecorder.Migration.objects.filter() which I see you have used too. 👍

@zerolab zerolab merged commit ec197c0 into wagtail:main Nov 4, 2022
gasman added a commit to gasman/wagtail-review that referenced this pull request Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ValueError: Related model 'wagtailcore.pagerevision' cannot be resolved
4 participants