nautobot-app-device-onboarding
nautobot-app-device-onboarding copied to clipboard
Leftover onboardingtask ObjectChange records after migration to 2.0 causes remove_stale_contenttypes to fail
trafficstars
Environment
- Python version: 3.8
- Nautobot version: 2.0.5
- nautobot-device-onboarding version: 3.0.1
After upgrading Nautobot from 1.6.X to 2.0.5 i encountered the following issue during the post_upgradeprocedure:
Removing stale content types...
Traceback (most recent call last):
File "/opt/nautobot/bin/nautobot-server", line 8, in <module>
sys.exit(main())
File "/opt/nautobot/lib64/python3.8/site-packages/nautobot/core/cli/__init__.py", line 54, in main
run_app(
File "/opt/nautobot/lib64/python3.8/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.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/nautobot/lib64/python3.8/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.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/nautobot/lib64/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/nautobot/lib64/python3.8/site-packages/nautobot/core/management/commands/post_upgrade.py", line 129, in handle
call_command("remove_stale_contenttypes", interactive=False)
File "/opt/nautobot/lib64/python3.8/site-packages/django/core/management/__init__.py", line 181, in call_command
return command.execute(*args, **defaults)
File "/opt/nautobot/lib64/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/nautobot/lib64/python3.8/site-packages/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py", line 83, in handle
ct.delete()
File "/opt/nautobot/lib64/python3.8/site-packages/django/db/models/base.py", line 966, in delete
collector.collect([self], keep_parents=keep_parents)
File "/opt/nautobot/lib64/python3.8/site-packages/django/db/models/deletion.py", line 302, in collect
raise ProtectedError(
django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'ContentType' because they are referenced through protected foreign keys: 'ObjectChange.changed_object_type'.", {<ObjectChange: [...]
This could be resolved by running the following command in nbshell:
ObjectChange.objects.filter(changed_object_type=ContentType.objects.get(model="onboardingtask")).delete()
After that the post_upgrade was successful.
Caused by https://github.com/nautobot/nautobot/issues/4862
Proposed fix in nautobot/nautobot#4863
The core fix is useful but I think this bug also needs to be addressed in this app.