No longer possible to query for prefixes or IP ranges containing another prefix via graphql (Netbox 4.3) #11345

Closed
opened 2025-12-29 21:43:58 +01:00 by adam · 6 comments
Owner

Originally created by @mraerino on GitHub (Jul 3, 2025).

Originally assigned to: @mraerino on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.3.3

Python Version

3.12

Steps to Reproduce

In Netbox 4.2.9 it was possible to run a query like this, which returns prefixes containing another prefix:

query listContainingPrefixes($prefix: String!) {
  prefix_list(filters: {contains: $prefix}) {
    id
    prefix
  }
  ip_range_list(filters: {contains: $prefix}) {
    id
    start_address
    end_address
  }
}

This is no longer possible on Netbox 4.3, the contains filter has been removed from the schema.

Expected Behavior

A graphql filter on the Prefix and IPRange models that allows querying for instances containing a certain prefix.

Observed Behavior

No filter attribute to query for instances containing a prefix

Originally created by @mraerino on GitHub (Jul 3, 2025). Originally assigned to: @mraerino on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.3.3 ### Python Version 3.12 ### Steps to Reproduce In Netbox 4.2.9 it was possible to run a query like this, which returns prefixes containing another prefix: ```gql query listContainingPrefixes($prefix: String!) { prefix_list(filters: {contains: $prefix}) { id prefix } ip_range_list(filters: {contains: $prefix}) { id start_address end_address } } ``` This is no longer possible on Netbox 4.3, the `contains` filter has been removed from the schema. ### Expected Behavior A graphql filter on the Prefix and IPRange models that allows querying for instances containing a certain prefix. ### Observed Behavior No filter attribute to query for instances containing a prefix
adam added the type: bugstatus: acceptedtopic: GraphQLseverity: low labels 2025-12-29 21:43:58 +01:00
adam closed this issue 2025-12-29 21:43:58 +01:00
Author
Owner

@sleepinggenius2 commented on GitHub (Jul 3, 2025):

I'm not sure of the syntax for IP ranges, but prefixes looks like it would just need something like the following code added to PrefixFilter in ipam.graphql.filters:

    @strawberry_django.filter_field()
    def contains(self, value: list[str], prefix) -> Q:
        if not value:
            return Q()
        q = Q()
        for subnet in value:
            try:
                query = str(netaddr.IPNetwork(subnet.strip()).cidr)
                q |= Q(prefix__net_contains=query)
            except (AddrFormatError, ValueError):
                return Q()
        return q
@sleepinggenius2 commented on GitHub (Jul 3, 2025): I'm not sure of the syntax for IP ranges, but prefixes looks like it would just need something like the following code added to `PrefixFilter` in `ipam.graphql.filters`: ```python @strawberry_django.filter_field() def contains(self, value: list[str], prefix) -> Q: if not value: return Q() q = Q() for subnet in value: try: query = str(netaddr.IPNetwork(subnet.strip()).cidr) q |= Q(prefix__net_contains=query) except (AddrFormatError, ValueError): return Q() return q ```
Author
Owner

@mraerino commented on GitHub (Jul 4, 2025):

Maintainers can assign me to this, i would be willing to provide a fix based on the suggestion of @sleepinggenius2 unless they want to provide the fix

@mraerino commented on GitHub (Jul 4, 2025): Maintainers can assign me to this, i would be willing to provide a fix based on the suggestion of @sleepinggenius2 unless they want to provide the fix
Author
Owner

@arthanson commented on GitHub (Jul 8, 2025):

@mraerino assigning to you

@arthanson commented on GitHub (Jul 8, 2025): @mraerino assigning to you
Author
Owner

@jnovinger commented on GitHub (Jul 25, 2025):

How goes the work on this, @mraerino ?

@jnovinger commented on GitHub (Jul 25, 2025): How goes the work on this, @mraerino ?
Author
Owner

@mraerino commented on GitHub (Aug 3, 2025):

tackling this now, sorry for the delay

@mraerino commented on GitHub (Aug 3, 2025): tackling this now, sorry for the delay
Author
Owner

@mraerino commented on GitHub (Aug 3, 2025):

PR ready

@mraerino commented on GitHub (Aug 3, 2025): PR ready
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11345