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

Keyerror 'rack' in fields_cache encountered while importing data #8

Open
abhi1693 opened this issue Apr 7, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@abhi1693
Copy link
Member

abhi1693 commented Apr 7, 2023

NetBox version

v3.4.7

Python version

3.10

Steps to Reproduce

Install a fresh instance and load the 3.4 demo data from https://github.com/netbox-community/netbox-demo-data/blob/master/netbox-demo-v3.4.json

Expected Behavior

The data is loaded successfully

Observed Behavior

This is caused by commit at netbox-community/netbox@2883fa1

Traceback (most recent call last):f-user-group) ✗ python manage.py loaddata ../../netbox-demo-data/netbox-demo-v3.4.json                                                                   git:(feat/10600-cf-user-group|●1✚8 
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 189, in __get__
    rel_obj = self.field.get_cached_value(instance)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/mixins.py", line 15, in get_cached_value
    return instance._state.fields_cache[cache_name]
KeyError: 'rack'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/asaharan/PycharmProjects/netbox-patches/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/loaddata.py", line 102, in handle
    self.loaddata(fixture_labels)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/loaddata.py", line 163, in loaddata
    self.load_label(fixture_label)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/loaddata.py", line 253, in load_label
    if self.save_obj(obj):
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/loaddata.py", line 209, in save_obj
    obj.save(using=self.using)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/serializers/base.py", line 288, in save
    models.Model.save_base(self.object, using=using, raw=True, **kwargs)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 878, in save_base
    post_save.send(
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 176, in send
    return [
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/home/asaharan/PycharmProjects/netbox-patches/netbox/dcim/signals.py", line 54, in assign_virtualchassis_master
    master.save()
  File "/home/asaharan/PycharmProjects/netbox-patches/netbox/dcim/models/devices.py", line 805, in save
    if self.rack and self.rack.location:
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 207, in __get__
    rel_obj = self.get_object(instance)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 170, in get_object
    return qs.get(self.field.get_reverse_related_filter(instance))
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 650, in get
    raise self.model.DoesNotExist(
dcim.models.racks.Rack.DoesNotExist: Problem installing fixture '/home/asaharan/PycharmProjects/netbox-patches/netbox/../../netbox-demo-data/netbox-demo-v3.4.json': Rack matching query does not exist.
@abhi1693 abhi1693 transferred this issue from netbox-community/netbox Apr 7, 2023
@abhi1693 abhi1693 added the bug Something isn't working label Apr 7, 2023
@jeremystretch
Copy link
Member

This was triggered by this change in NetBox. It turns out that the devices are being imported before the racks, so the call to save() on the device instance is raising a DoesNotExist exception.

To fix this properly, we'll need to change the order in which the models are exported when generating the demo data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants