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

Importing CSV with Foreign Key fails #6719

Open
finishshell opened this issue Jan 3, 2025 · 1 comment
Open

Importing CSV with Foreign Key fails #6719

finishshell opened this issue Jan 3, 2025 · 1 comment
Labels
type: bug Something isn't working as expected

Comments

@finishshell
Copy link

Environment

  • Nautobot version (Docker tag too if applicable): 2.3.15
  • Python version: 3.12
  • Database platform, version: Postgress 14.15
  • Middleware(s):

Steps to Reproduce

  1. Exported devices from one nautobot instance running the same version of code
  2. Tried to import the exported cvs file into the second instance of nautobot
  3. Error shows saying type object 'ContentType' has no attribute 'label_lower'"

Expected Behavior

I expected the devices to be created if no other dependencies where required

Observed Behavior

Traceback (most recent call last):
File "/opt/nautobot/lib/python3.10/site-packages/celery/app/trace.py", line 477, in trace_task
R = retval = fun(*args, **kwargs)
File "/opt/nautobot/lib/python3.10/site-packages/celery/app/trace.py", line 760, in protected_call
return self.run(*args, **kwargs)
File "/opt/nautobot/lib/python3.10/site-packages/nautobot/extras/jobs.py", line 1138, in run_job
result = job(*args, **kwargs)
File "/opt/nautobot/lib/python3.10/site-packages/nautobot/extras/jobs.py", line 151, in call
return self.run(*args, **deserialized_kwargs)
File "/opt/nautobot/lib/python3.10/site-packages/nautobot/core/jobs/init.py", line 330, in run
new_objs, validation_failed = self._perform_atomic_operation(data, serializer_class, queryset)
File "/opt/nautobot/lib/python3.10/site-packages/nautobot/core/jobs/init.py", line 255, in _perform_atomic_operation
new_objs, validation_failed = self._perform_operation(data, serializer_class, queryset)
File "/opt/nautobot/lib/python3.10/site-packages/nautobot/core/jobs/init.py", line 268, in _perform_operation
if serializer.is_valid():
File "/opt/nautobot/lib/python3.10/site-packages/rest_framework/serializers.py", line 223, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/opt/nautobot/lib/python3.10/site-packages/rest_framework/serializers.py", line 442, in run_validation
value = self.to_internal_value(data)
File "/opt/nautobot/lib/python3.10/site-packages/rest_framework/serializers.py", line 499, in to_internal_value
validated_value = field.run_validation(primitive_value)
File "/opt/nautobot/lib/python3.10/site-packages/rest_framework/relations.py", line 155, in run_validation
return super().run_validation(data)
File "/opt/nautobot/lib/python3.10/site-packages/rest_framework/fields.py", line 538, in run_validation
value = self.to_internal_value(data)
File "/opt/nautobot/lib/python3.10/site-packages/nautobot/core/api/fields.py", line 215, in to_internal_value
elif related_model is not None and related_model.label_lower == "auth.group":
AttributeError: type object 'ContentType' has no attribute 'label_lower'

As per request on the slack channel, creating an issue for this

@finishshell finishshell added triage This issue is new and has not been reviewed. type: bug Something isn't working as expected labels Jan 3, 2025
@glennmatthews
Copy link
Contributor

Appears to be a bug here in that related_model.label_lower should probably be related_model._meta.label_lower. Need to come up with a good test case to reproduce this issue though and identify why it wasn't caught by existing CSV tests.

@glennmatthews glennmatthews removed the triage This issue is new and has not been reviewed. label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants