GraphQL StrFilterLookup filter on prefix field causes unexpected error with IPNetworkField #11648

Closed
opened 2025-12-29 21:48:03 +01:00 by adam · 3 comments
Owner

Originally created by @rinna11 on GitHub (Sep 25, 2025).

Originally assigned to: @rinna11 on GitHub.

NetBox Edition

NetBox Community

NetBox Version

v4.4.1

Python Version

3.12

Steps to Reproduce

  1. Use GraphQL to query aggregate_list with the following filter:
aggregate_list(filters: {
  prefix: {
    prefix: {
      i_regex: "^(?!10\\.)[^:]+$"
    }
  }
}) {
  prefix
}
  1. Run the query.

Expected Behavior

  • The query should return prefixes that match the regex pattern (e.g., IPv6 only).
  • Same return we can expect not only for i_regex , but also for the other StrFilterLookup fields like exact, contains and so on.
  • No error should occur, since the query syntax is valid.

Observed Behavior

  • The query fails with the following error:
{
  "data": null,
  "errors": [
    {
      "message": "Unsupported lookup 'prefix__iregex' for IPNetworkField or join on the field not permitted.",
      "locations": [
        {
          "line": 36,
          "column": 3
        }
      ],
      "path": [
        "aggregate_list"
      ]
    }
  ]
}
  • We tried to other StrFilterLookup Fields, such as contains but it also did not work.
  • No results are returned.

Background:
Before upgrading to NetBox 4.4.1 from 4.1.11, we used the following GraphQL query to filter IPv6 prefixes:

aggregate_list(filters: {family: 6}) {
  prefix
}

This query worked correctly in version 4.1.11. However, after upgrading to 4.4.1, the family filter is no longer supported.
To work around this, we tried using a regex filter on the prefix field to exclude IPv4 addresses and target IPv6 only.

Originally created by @rinna11 on GitHub (Sep 25, 2025). Originally assigned to: @rinna11 on GitHub. ### NetBox Edition NetBox Community ### NetBox Version v4.4.1 ### Python Version 3.12 ### Steps to Reproduce 1. Use GraphQL to query `aggregate_list` with the following filter: ``` aggregate_list(filters: { prefix: { prefix: { i_regex: "^(?!10\\.)[^:]+$" } } }) { prefix } ``` 2. Run the query. ### Expected Behavior - The query should return prefixes that match the regex pattern (e.g., IPv6 only). - Same return we can expect not only for `i_regex` , but also for the other `StrFilterLookup` fields like exact, contains and so on. - No error should occur, since the query syntax is valid. ### Observed Behavior - The query fails with the following error: ``` { "data": null, "errors": [ { "message": "Unsupported lookup 'prefix__iregex' for IPNetworkField or join on the field not permitted.", "locations": [ { "line": 36, "column": 3 } ], "path": [ "aggregate_list" ] } ] } ``` - We tried to other StrFilterLookup Fields, such as `contains` but it also did not work. - No results are returned. Background: Before upgrading to NetBox 4.4.1 from 4.1.11, we used the following GraphQL query to filter IPv6 prefixes: ``` aggregate_list(filters: {family: 6}) { prefix } ``` This query worked correctly in version 4.1.11. However, after upgrading to 4.4.1, the family filter is no longer supported. To work around this, we tried using a regex filter on the prefix field to exclude IPv4 addresses and target IPv6 only.
adam added the type: bugstatus: acceptednetboxtopic: GraphQLseverity: low labels 2025-12-29 21:48:03 +01:00
adam closed this issue 2025-12-29 21:48:04 +01:00
Author
Owner

@rinna11 commented on GitHub (Oct 13, 2025):

Hello @arthanson,
I would like to create a pull request to address this issue as well as #20423.
Both issues can be resolved once GraphQL supports filtering by family (e.g., IPv4 or IPv6).
Would it be possible to assign me so I can proceed with creating the pull request? Thank you for your consideration.

@rinna11 commented on GitHub (Oct 13, 2025): Hello @arthanson, I would like to create a pull request to address this issue as well as #20423. Both issues can be resolved once GraphQL supports filtering by `family` (e.g., IPv4 or IPv6). Would it be possible to assign me so I can proceed with creating the pull request? Thank you for your consideration.
Author
Owner

@rinna11 commented on GitHub (Oct 16, 2025):

Hello @jnovinger, I would like to create a pull request to support the family field for AggregateFilter and PrefixFilter.

Just taking a quick look, it seems that both AggregateFilterSet and AggregateFilterForm include a family field and both of them might be called from AggregateFilter. Based on that, I tried adding the following line to the AggregateFilter so that we might be able to use the family field:

family: int | None = strawberry_django.filter_field()

After doing this, the family field appeared in the GraphQL schema as expected. However, when I tried to query it, the query returned an error stating that "Cannot resolve keyword 'family' into field."
So I’m wondering: even though AggregateFilterSet and AggregateFilterForm include the family field, are they not actually supported in the GraphQL filter? Is there an additional step required to enable it, or is this an intentional limitation?

The family field our team used to rely on is no longer working after upgrading to v4.4.1 and we are having trouble now.
Any clarification would be greatly appreciated. I would be happy to contribute and submit a PR if this change is welcome. Please feel free to assign me. Thank you very much!

@rinna11 commented on GitHub (Oct 16, 2025): Hello @jnovinger, I would like to create a pull request to support the `family` field for `AggregateFilter` and `PrefixFilter`. Just taking a quick look, it seems that both [AggregateFilterSet](https://github.com/netbox-community/netbox/blob/dbc71158ec67ddd17f9434272ec62e33b4aba23d/netbox/ipam/filtersets.py#L152) and [AggregateFilterForm](https://github.com/netbox-community/netbox/blob/dbc71158ec67ddd17f9434272ec62e33b4aba23d/netbox/ipam/forms/filtersets.py#L97C7-L97C26) include a `family` field and both of them might be called from `AggregateFilter`. Based on that, I tried adding the following line to the [AggregateFilter](https://github.com/netbox-community/netbox/blob/dbc71158ec67ddd17f9434272ec62e33b4aba23d/netbox/ipam/graphql/filters.py#L81) so that we might be able to use the `family` field: ```python family: int | None = strawberry_django.filter_field() ``` After doing this, the `family` field appeared in the GraphQL schema as expected. However, when I tried to query it, the query returned an error stating that "Cannot resolve keyword 'family' into field." So I’m wondering: even though [AggregateFilterSet](https://github.com/netbox-community/netbox/blob/dbc71158ec67ddd17f9434272ec62e33b4aba23d/netbox/ipam/filtersets.py#L152) and [AggregateFilterForm](https://github.com/netbox-community/netbox/blob/dbc71158ec67ddd17f9434272ec62e33b4aba23d/netbox/ipam/forms/filtersets.py#L97C7-L97C26) include the `family` field, are they not actually supported in the GraphQL filter? Is there an additional step required to enable it, or is this an intentional limitation? The `family` field our team used to rely on is no longer working after upgrading to v4.4.1 and we are having trouble now. Any clarification would be greatly appreciated. I would be happy to contribute and submit a PR if this change is welcome. Please feel free to assign me. Thank you very much!
Author
Owner

@jeremystretch commented on GitHub (Oct 16, 2025):

@rinna11 please don't ping individuals unless you're specifically addressing something they've said on the thread. This project has several maintainers and any of us can assign an issue to a volunteer.

Thanks for looking into this. I've assigned this to your for a PR.

@jeremystretch commented on GitHub (Oct 16, 2025): @rinna11 please don't ping individuals unless you're specifically addressing something they've said on the thread. This project has several maintainers and any of us can assign an issue to a volunteer. Thanks for looking into this. I've assigned this to your for a PR.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11648