mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Fixes #16216: Fix validation of JournalEntry when referenced by a custom field
This commit is contained in:
parent
02755d43d5
commit
09c1228712
@ -43,7 +43,7 @@ class JournalEntrySerializer(NetBoxModelSerializer):
|
|||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
|
|
||||||
# Validate that the parent object exists
|
# 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:
|
try:
|
||||||
data['assigned_object_type'].get_object_for_this_type(id=data['assigned_object_id'])
|
data['assigned_object_type'].get_object_for_this_type(id=data['assigned_object_id'])
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
@ -51,10 +51,7 @@ class JournalEntrySerializer(NetBoxModelSerializer):
|
|||||||
f"Invalid assigned_object: {data['assigned_object_type']} ID {data['assigned_object_id']}"
|
f"Invalid assigned_object: {data['assigned_object_type']} ID {data['assigned_object_id']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Enforce model validation
|
return super().validate(data)
|
||||||
super().validate(data)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
@extend_schema_field(serializers.JSONField(allow_null=True))
|
||||||
def get_assigned_object(self, instance):
|
def get_assigned_object(self, instance):
|
||||||
|
Loading…
Reference in New Issue
Block a user