Skip to content

Fixes #18669 - Populate custom field default values #19115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion netbox/ipam/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ def save(self, *args, **kwargs):
role=FHRP_PROTOCOL_ROLE_MAPPINGS.get(self.cleaned_data['protocol'], IPAddressRoleChoices.ROLE_VIP),
assigned_object=instance
)
ipaddress.populate_custom_field_defaults()
ipaddress.save()

# Check that the new IPAddress conforms with any assigned object-level permissions
Expand Down
8 changes: 8 additions & 0 deletions netbox/netbox/models/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ def clean(self):
if cf.required and cf.name not in self.custom_field_data:
raise ValidationError(_("Missing required custom field '{name}'.").format(name=cf.name))

def save(self, *args, **kwargs):
# Populate default values if omitted
for cf in self.custom_fields.filter(default__isnull=False):
if cf.name not in self.custom_field_data:
self.custom_field_data[cf.name] = cf.default

super().save(*args, **kwargs)


class CustomLinksMixin(models.Model):
"""
Expand Down