nautobot: Postgres 10: 2.0 Migration error: `cannot ALTER TABLE "extras_jobresult" because it has pending trigger events`

Environment

  • Nautobot version (Docker tag too if applicable): 2.0.3
  • Python version: 3.9
  • Database platform, version: PostgreSQL v10.17
  • Middleware(s):

Steps to Reproduce

  1. Have JobResult objects in Nautobot 1.6.2
  2. Upgrade to Nautobot 2.0.3
  3. Run nautobot-server post_upgrade

Expected Behavior

Migrations to complete successfully

Observed Behavior

Applying extras.0087_job__celery_task_fields__dryrun_support...Traceback (most recent call last):
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
    psycopg2.errors.ObjectInUse: cannot ALTER TABLE "extras_jobresult" because it has pending trigger events
 
 
The above exception was the direct cause of the following exception:
 
Traceback (most recent call last):
  File "/opt/nautobot/bin/nautobot-server", line 8, in <module>
    sys.exit(main())
  File "/opt/nautobot/lib64/python3.9/site-packages/nautobot/core/cli/__init__.py", line 54, in main
    run_app(
  File "/opt/nautobot/lib64/python3.9/site-packages/nautobot/core/runner/runner.py", line 297, in run_app
    management.execute_from_command_line([runner_name, command] + command_args)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/nautobot/lib64/python3.9/site-packages/nautobot/core/management/commands/post_upgrade.py", line 100, in handle
    call_command(
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/__init__.py", line 181, in call_command
    return command.execute(*args, **defaults)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/opt/nautobot/lib64/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 "/opt/nautobot/lib64/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 "/opt/nautobot/lib64/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/opt/nautobot/lib64/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 "/opt/nautobot/lib64/python3.9/site-packages/django/db/migrations/operations/fields.py", line 244, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/base/schema.py", line 608, in alter_field
    self._alter_field(model, old_field, new_field, old_type, new_type,
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/postgresql/schema.py", line 196, in _alter_field
    super()._alter_field(
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/base/schema.py", line 785, in _alter_field
    self.execute(
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/base/schema.py", line 145, in execute
    cursor.execute(sql, params)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  django.db.utils.OperationalError: cannot ALTER TABLE "extras_jobresult" because it has pending trigger events

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

I was finally able to replicate on postgresql 10.17 with this record:

JobResult.objects.create(name="test jobresult null fields 2", obj_type=ContentType.objects.get_for_model(Job), user=User.objects.first(), status="completed", data=None, job_model=None, schedule=None, job_kwargs=None, job_id=uuid.uuid4())

For some reason it was only failing if user_id was not null.

Now to fix the original issue, setting the default value for task_args fixed the migration:

update extras_jobresult set task_args = '[]' WHERE task_args is NULL;