Skip to content

Model breaks NetBox upgrade script (remove_stale_contenttypes step) if field references another custom object #141

@averyhabbott

Description

@averyhabbott

Plugin Version

0.1.0

NetBox Version

4.3.4

Python Version

3.12.7

Steps to Reproduce

Run "sudo ./opt/netbox/upgrade.sh"
Doesn't matter whether or not you have a new version of NetBox staged

Expected Behavior

Upgrade script runs successfully

Observed Behavior

Script fails during "remove_stale_contenttypes" step

Removing stale content types (python3 netbox/manage.py remove_stale_contenttypes --no-input)...
Traceback (most recent call last):
  File "/opt/netbox-4.3.5/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox-4.3.5/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox-4.3.5/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox-4.3.5/venv/lib/python3.12/site-packages/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox-4.3.5/venv/lib/python3.12/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.3.5/venv/lib/python3.12/site-packages/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py", line 102, in handle
    ct.delete()
  File "/opt/netbox-4.3.5/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1280, in delete
    collector.collect([self], keep_parents=keep_parents)
  File "/opt/netbox-4.3.5/venv/lib/python3.12/site-packages/django/db/models/deletion.py", line 350, in collect
    raise ProtectedError(
django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'ContentType' because they are referenced through protected foreign keys: 'CustomObjectTypeField.related_object_type'.", {<CustomObjectTypeField: DHCP Environment>})

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions