Skip to content

Commit 6476408

Browse files
committed
fix: handle ManyToMany and ForeignKey fields in content type preparation for matcher
Signed-off-by: Michal Fiedorowicz <mfiedorowicz@netboxlabs.com>
1 parent 7538c8b commit 6476408

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

netbox_diode_plugin/api/matcher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,11 @@ def _prepare_data(self, data: dict) -> dict:
449449
field = self.model_class._meta.get_field(field_name)
450450
# special handling for object type -> content type id
451451
if field.is_relation and hasattr(field, "related_model") and field.related_model == ContentType:
452-
prepared[field_name] = content_type_id(value)
452+
# Handle ManyToMany fields (list of object types) and ForeignKey fields (single object type)
453+
if isinstance(value, list):
454+
prepared[field_name] = [content_type_id(v) for v in value]
455+
else:
456+
prepared[field_name] = content_type_id(value)
453457
else:
454458
prepared[field_name] = value
455459

0 commit comments

Comments
 (0)