Skip to content

Commit

Permalink
Fixes #16216: Fix validation of JournalEntry when referenced by a cus…
Browse files Browse the repository at this point in the history
…tom field
  • Loading branch information
jeremystretch committed May 21, 2024
1 parent 233b902 commit 8a3d5e1
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions netbox/extras/api/serializers_/journaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ class Meta:
def validate(self, data):

# Validate that the parent object exists
if 'assigned_object_type' in data and 'assigned_object_id' in data:
if not self.nested and 'assigned_object_type' in data and 'assigned_object_id' in data:
try:
data['assigned_object_type'].get_object_for_this_type(id=data['assigned_object_id'])
except ObjectDoesNotExist:
raise serializers.ValidationError(
f"Invalid assigned_object: {data['assigned_object_type']} ID {data['assigned_object_id']}"
)

# Enforce model validation
super().validate(data)

return data
return super().validate(data)

@extend_schema_field(serializers.JSONField(allow_null=True))
def get_assigned_object(self, instance):
Expand Down

0 comments on commit 8a3d5e1

Please sign in to comment.