Skip to content

Conversation

@pitan
Copy link

@pitan pitan commented Jan 21, 2026

Summary

Fixes a false-negative validation when applying custom_field_data from YAML initializers.
A custom field could be incorrectly reported as “not enabled for ”, even though it is enabled.

Root cause

ObjectType.objects.get_for_model() returns NetBox's ObjectType, while CustomField.object_types
is a queryset of Django ContentType (or a different type depending on NetBox version).
Because the membership check compares different model classes, ct not in cf.object_types.all()
can evaluate to True even when the underlying content type matches.

Changes

  • Compare by primary key using .filter(pk=ct.pk).exists() instead of ct in queryset

Reproduction

  1. Create a Custom Field assigned to IPAM > Prefix
  2. Reference it under custom_field_data in prefixes.yml
  3. Run load_initializer_data
    Before: prints “Custom field ... is not enabled for Prefix's model” and the value is not applied
    After: no false warning and the custom field value is applied

Tested

  • Tested on: NetBox v4.4.10 / netbox-initializers v4.4.0

@tobiasge tobiasge merged commit bf4a0ca into tobiasge:main Jan 21, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants