netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Cannot filter ip range based on parent prefix

Open kuon opened this issue 1 year ago • 3 comments

Deployment Type

Self-hosted

NetBox Version

v4.1.1

Python Version

3.12

Steps to Reproduce

Create the following graphql query:

{
  ip_range_list(filters: {parent: {exact: "10.20.0.0/16"}}) {
    id
  }
}

Expected Behavior

I expect the same result as this API call:

/api/ipam/ip-ranges/?parent=10.20.0.0/16

And it is mentioned in this issue:

https://github.com/netbox-community/netbox/issues/13313

Also the IPRangeFilter graphql type has a parent: StrFilterLookup field.

Observed Behavior

Error is thrown:

{
  "data": null,
  "errors": [
    {
      "message": "Cannot resolve keyword 'parent' into field. Choices are: bookmarks, comments, contacts, created, custom_field_data, description, end_address, id, journal_entries, last_updated, mark_utilized, role, role_id, size, start_address, status, subscriptions, tagged_items, tags, tenant, tenant_id, vrf, vrf_id",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "ip_range_list"
      ]
    }
  ]
}

kuon avatar Oct 06 '24 01:10 kuon

Also affects ip address lists too.

tom0010 avatar Oct 07 '24 15:10 tom0010

Just to mention that we hit the same issue in an installation at one of our major customers in Germany. Hoping that there is a chance that this might increase the priority of fixing this bug.

If there is anything where I can support (keep in mind that I am not a Django developer) please let me know.

Please refer to https://netdev-community.slack.com/archives/C01P0FRSXRV/p1728394236998439 for latest state of discussion of this issue in Slack

svluder avatar Oct 08 '24 14:10 svluder

Also affects ip address lists too.

Can confirm, we are also affected. Deployment version is 4.1.4.

loulecrivain avatar Oct 23 '24 11:10 loulecrivain

Fixed in my branch here: https://github.com/jeremypng/netbox/tree/refs/heads/graphql-filter-redesign

fixed query:

query GetIPRange {
  ip_range_list (filters: {parent: [""192.168.1.0/25""]}){
    id
    start_address
    end_address
  }
}

results:

{
  "data": {
    "ip_range_list": [
      {
        "id": "1",
        "start_address": "192.168.1.0/22",
        "end_address": "192.168.1.49/22"
      },
      {
        "id": "2",
        "start_address": "192.168.1.50/22",
        "end_address": "192.168.1.99/22"
      }
    ]
  }
}

If you'll assign this to me I'll tag it in the PR

jeremypng avatar Jan 22 '25 23:01 jeremypng

I expect the same result as this API call:

Please note that parity between the REST and GraphQL APIs is not and has never been a design goal. While they are generally comparable in functionality, specific filters available in one API might not be made available in the other, for various reasons. In this case, the parent filter has not been made available for IP ranges in the GraphQL API.

Per @jeremypng's comment above, this looks like it will be implemented as part of the GraphQL API change being explored for #7598.

jeremystretch avatar Feb 07 '25 20:02 jeremystretch

Blocked by #7598

jeremystretch avatar Feb 07 '25 20:02 jeremystretch

I can confirm that this has been resolved as part of the work on #7598. For example, the following query will return all IP ranges within the prefix 10.1.0.0/24:

{
  ip_range_list(filters: {parent: "10.1.0.0/24"}) {
    id
  }
}

This change will be implemented in NetBox v4.3.

jeremystretch avatar Mar 10 '25 19:03 jeremystretch