Ordering of DCIM models break dumpdata/loaddata functionality #3122

Closed
opened 2025-12-29 18:25:54 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Jan 6, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.11

Steps to Reproduce

  1. Create at least one cable terminated to a power feed
  2. Export existing data with ./manage.py dumpdata -o <filename> --natural-foreign --natural-primary --indent 4 --format json
  3. Load the JSON-formatted data into a new database with ./manage.py loaddata <filename>

Expected Behavior

All data should be imported successfully

Observed Behavior

An AttrbiuteError is raised:

AttributeError: Problem installing fixture '/home/jstretch/netbox/netbox/../demo_data.json': 'NoneType' object has no attribute 'cable'

This is because Django is exporting Cables prior to exporting PowerFeeds. Upon import, Django is attempting to create cables to terminations that don't yet exist, hence the exception.

Presumably, this can be fixed by moving the Cable model definition so that it comes after PowerFeed in models.py.

Originally created by @jeremystretch on GitHub (Jan 6, 2020). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.6.8 * NetBox version: 2.6.11 ### Steps to Reproduce 1. Create at least one cable terminated to a power feed 2. Export existing data with `./manage.py dumpdata -o <filename> --natural-foreign --natural-primary --indent 4 --format json` 3. Load the JSON-formatted data into a new database with `./manage.py loaddata <filename>` ### Expected Behavior All data should be imported successfully ### Observed Behavior An `AttrbiuteError` is raised: ``` AttributeError: Problem installing fixture '/home/jstretch/netbox/netbox/../demo_data.json': 'NoneType' object has no attribute 'cable' ``` This is because Django is exporting Cables prior to exporting PowerFeeds. Upon import, Django is attempting to create cables to terminations that don't yet exist, hence the exception. Presumably, this can be fixed by moving the Cable model definition so that it comes after PowerFeed in `models.py`.
adam added the type: bugstatus: accepted labels 2025-12-29 18:25:54 +01:00
adam closed this issue 2025-12-29 18:25:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3122