From d01454c753d37c841f731c19a0d3b6c0eb95a62b Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Wed, 29 Apr 2026 15:03:52 +0200 Subject: [PATCH] fix(ipam): Omit None values from AddObject URL parameters Update AddObject.get_url() to skip parameters that resolve to None, preventing invalid query strings. Adjust VLAN-to-Prefix action to use scope_type/scope instead of site field. Fixes #22031 --- netbox/ipam/views.py | 7 +++++-- netbox/netbox/ui/actions.py | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 0c784f8ac..898db4b7e 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -1636,8 +1636,11 @@ class VLANView(generic.ObjectView): actions.AddObject( 'ipam.prefix', url_params={ - 'tenant': lambda ctx: ctx['object'].tenant.pk if ctx['object'].tenant else None, - 'site': lambda ctx: ctx['object'].site.pk if ctx['object'].site else None, + 'tenant': lambda ctx: ctx['object'].tenant_id, + 'scope_type': lambda ctx: ( + ContentType.objects.get_for_model(Site).pk if ctx['object'].site_id else None + ), + 'scope': lambda ctx: ctx['object'].site_id, 'vlan': lambda ctx: ctx['object'].pk, }, label=_('Add a Prefix'), diff --git a/netbox/netbox/ui/actions.py b/netbox/netbox/ui/actions.py index 7579e7b93..ef0b0f66f 100644 --- a/netbox/netbox/ui/actions.py +++ b/netbox/netbox/ui/actions.py @@ -92,14 +92,18 @@ class LinkAction(PanelAction): """ url = reverse(self.view_name, kwargs=self.view_kwargs) if self.url_params: - # If the param value is callable, call it with the context and save the result. - url_params = { - k: v(context) if callable(v) else v for k, v in self.url_params.items() - } + url_params = {} + for key, value in self.url_params.items(): + # If the param value is callable, call it with the context and save the result. + value = value(context) if callable(value) else value + # Omit parameters whose value resolved to None + if value is not None: + url_params[key] = value # Set the return URL if not already set and an object is available. if 'return_url' not in url_params and 'object' in context: url_params['return_url'] = context['object'].get_absolute_url() - url = f'{url}?{urlencode(url_params)}' + if url_params: + url = f'{url}?{urlencode(url_params)}' return url def get_context(self, context):