Skip to content

Commit aa4794d

Browse files
committed
custom_field object_type was renamed to related_object_type in netbox 4.0
1 parent 50d077d commit aa4794d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/netbox_initializers/initializers/custom_fields.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,30 @@ def load_data(self):
6161
if cf_details.get("is_cloneable", None) is not None:
6262
custom_field.is_cloneable = cf_details["is_cloneable"]
6363

64-
# object_type should only be applied when type is object, multiobject
64+
# object_type was renamed to related_object_type in netbox 4.0
6565
if cf_details.get("object_type"):
66+
print(
67+
f"⚠️ Unable to create Custom Field '{cf_name}': please rename object_type "
68+
+ "to related_object_type"
69+
)
70+
custom_field.delete()
71+
continue
72+
73+
# related_object_type should only be applied when type is object, multiobject
74+
if cf_details.get("related_object_type"):
6675
if cf_details.get("type") not in (
6776
"object",
6877
"multiobject",
6978
):
7079
print(
71-
f"⚠️ Unable to create Custom Field '{cf_name}': object_type is "
80+
f"⚠️ Unable to create Custom Field '{cf_name}': related_object_type is "
7281
+ "supported only for object and multiobject types"
7382
)
7483
custom_field.delete()
7584
continue
76-
custom_field.object_type = get_class_for_class_path(cf_details["object_type"])
85+
custom_field.related_object_type = get_class_for_class_path(
86+
cf_details["related_object_type"]
87+
)
7788

7889
# validation_regex should only be applied when type is text, longtext, url
7990
if cf_details.get("validation_regex"):

src/netbox_initializers/initializers/yaml/custom_fields.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
# filter_logic: loose
101101
# on_objects:
102102
# - dcim.models.Location
103-
# object_type: ipam.models.IPAddress
103+
# related_object_type: ipam.models.IPAddress
104104
# object_field:
105105
# type: object
106106
# label: ASN
@@ -109,4 +109,4 @@
109109
# filter_logic: loose
110110
# on_objects:
111111
# - dcim.models.Device
112-
# object_type: ipam.models.ASN
112+
# related_object_type: ipam.models.ASN

0 commit comments

Comments
 (0)