netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.1k stars 2.58k forks source link

Graphql filters to same attribute #17883

Open SRF-rueeggdo opened 1 day ago

SRF-rueeggdo commented 1 day ago

Deployment Type

Self-hosted

Triage priority

N/A

NetBox Version

v4.1.4

Python Version

3.11

Steps to Reproduce

  1. execute the following query in the GraphiQL web interface. It should work.
  2. run the query below as a curl command. This will return an error.

GraphiQL:

{
  border_leaf_list: device_list(
    filters: {tag: "avd", virtual_chassis_member: false, status: "active", role: "border-leaf", site: "iplab"}
  ) {
    name
    loopback_interfaces: interfaces(filters: {type: {exact: "virtual"}}) {
      name
      description
      type
      ip_addresses {
        address
        vrf {
          name
        }
      }
    }
    svi_interfaces: interfaces(filters: {type: {exact: "bridge"}}) {
      name
      description
      type
      ip_addresses {
        address
      }
    }
  }
}

CLI:

curl -H "Authorization: Token YOURTOKEN" \
     -H "Content-Type: application/json" \
     -H "Accept: application/json" \
     https://YOURURL/graphql/ \
     --data '{"query": "query {border_leaf_list: device_list(filters: {tag: \"avd\", virtual_chassis_member: false, status: \"active\", role: \"border-leaf\", site: \"iplab\"}) {name loopback_interfaces: interfaces(filters: {type: {exact: \"virtual\"}}) {name description type ip_addresses {address vrf {name}}} svi_interfaces: interfaces(filters: {type: {exact: \"bridge\"}}) {name description type ip_addresses {address}}}}"}'

Expected Behavior

The query should return this.

{
  "data": {
    "border_leaf_list": [
      {
        "name": "ZHFER-SCB9211-A",
        "svi_interfaces": []
      },
      {
        "name": "ZHFER-SCB9211-B",
        "svi_interfaces": []
      }
    ]
  }
}

Observed Behavior

The curl command returns this insted.

{"data": null, "errors": [{"message": "Tried to prefetch 2 queries with different filters to the same attribute. Use `to_attr` in this case...", "locations": [{"line": 1, "column": 8}], "path": ["border_leaf_list"]}]}
arthanson commented 1 day ago

@SRF-rueeggdo Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

You have provided the expected output, but haven't provided how to setup the data to get this output, can you please provide steps that input the data for the GraphQL query to run against.