Missing LookupFilters for many fields in GraphQL API #9728

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

Originally created by @cybarox on GitHub (May 23, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.3

Python Version

3.10

Steps to Reproduce

Set description on a device to "akron"

Use integrated GraphQL Explorer and use following query

{
  # query field with LookupFilter
  QUERY1: device_list(filters: {description: {i_contains: "akron"}}) {
    name
  }
  # query field with missing LookupFilter
  QUERY2: device_list(filters: {name: {i_contains: "akron"}}) {
    name
  }
}

For some fields the LookupFilters are available e.g. description for the device object.

With the change to strawberry-django, many fields are missing the LookupFilter functions e.g. name field of device object.

Expected Behavior

Get correct result:

{
  "data": {
    "QUERY1": [
      {
        "name": "dmi01-akron-pdu01"
      }
    ],
    "QUERY2": [
      {
        "name": "dmi01-akron-pdu01"
      },
      {
        "name": "dmi01-akron-rtr01"
      },
      {
        "name": "dmi01-akron-sw01"
      }
    ]
  }
}

Observed Behavior

Get Error due to missing LookupFilter:

{
  "data": null,
  "errors": [
    {
      "message": "String cannot represent a non string value: {i_contains: \"akron\"}",
      "locations": [
        {
          "line": 5,
          "column": 39
        }
      ]
    }
  ]
}
Originally created by @cybarox on GitHub (May 23, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.3 ### Python Version 3.10 ### Steps to Reproduce Set description on a device to "akron" Use integrated GraphQL Explorer and use following query ```graphql { # query field with LookupFilter QUERY1: device_list(filters: {description: {i_contains: "akron"}}) { name } # query field with missing LookupFilter QUERY2: device_list(filters: {name: {i_contains: "akron"}}) { name } } ``` For some fields the LookupFilters are available e.g. description for the device object. With the change to strawberry-django, many fields are missing the LookupFilter functions e.g. name field of device object. ### Expected Behavior Get correct result: ```json { "data": { "QUERY1": [ { "name": "dmi01-akron-pdu01" } ], "QUERY2": [ { "name": "dmi01-akron-pdu01" }, { "name": "dmi01-akron-rtr01" }, { "name": "dmi01-akron-sw01" } ] } } ``` ### Observed Behavior Get Error due to missing LookupFilter: ```json { "data": null, "errors": [ { "message": "String cannot represent a non string value: {i_contains: \"akron\"}", "locations": [ { "line": 5, "column": 39 } ] } ] } ```
adam added the type: bugstatus: acceptedtopic: GraphQLseverity: medium labels 2025-12-29 21:21:41 +01:00
adam closed this issue 2025-12-29 21:21:41 +01:00
Author
Owner

@antoinekh commented on GitHub (May 30, 2024):

Hello,

Some others example in 4.0.3
OK on cluster_list

query Getcluster{
  cluster_list(filters: {name :{contains: "my-device"}, status: "active"}) {
    name
  }
}

But KO on device list

query GetDevice{
  device_list(filters: {name :{contains: "my-device"}, status: "active"}) {
    name
  }
}
@antoinekh commented on GitHub (May 30, 2024): Hello, Some others example in 4.0.3 OK on cluster_list ``` query Getcluster{ cluster_list(filters: {name :{contains: "my-device"}, status: "active"}) { name } } ``` But KO on device list ``` query GetDevice{ device_list(filters: {name :{contains: "my-device"}, status: "active"}) { name } } ```
Author
Owner

@cybarox commented on GitHub (Jun 7, 2024):

Hello I've tested again with the last release. The filter for the name field now functions as expected, thanks for the fix. We still have an issue to filter other fields. In our environment we need all IP and DNS data from specific clients of an specific site, if a client has a specific role and an interface that mac_address contains a special string. To archive that, we have used the following query (syntax is adapted to strawberry already)

query vendor_query($mac_vendor: String!, $facility_name: String!, $device_role: [String!]) {site_list(filters: {facility: { exact: $facility_name}}) {
    name
    custom_fields
    devices(filters: {role: $device_role}) {
        CLIENT_NAME: name
        interfaces(filters: {mac_address: { i_contains: $mac_vendor}}) {
            name
            CLIENT_MAC: mac_address
            ip_addresses {
                CLIENT_IP: address
                STATUS: status
                CLIENT_DNS: dns_name
            }
        }
        config_context
    }
}

Now the query results in:

{
  "data": null,
  "errors": [
    {
      "message": "String cannot represent a non string value: {i_contains: $mac_vendor}",
      "locations": [
        {
          "line": 6,
          "column": 43
        }
      ]
    }
  ]
}
@cybarox commented on GitHub (Jun 7, 2024): Hello I've tested again with the last release. The filter for the name field now functions as expected, thanks for the fix. We still have an issue to filter other fields. In our environment we need all IP and DNS data from specific clients of an specific site, if a client has a specific role and an interface that mac_address contains a special string. To archive that, we have used the following query (syntax is adapted to strawberry already) ```graphql query vendor_query($mac_vendor: String!, $facility_name: String!, $device_role: [String!]) {site_list(filters: {facility: { exact: $facility_name}}) { name custom_fields devices(filters: {role: $device_role}) { CLIENT_NAME: name interfaces(filters: {mac_address: { i_contains: $mac_vendor}}) { name CLIENT_MAC: mac_address ip_addresses { CLIENT_IP: address STATUS: status CLIENT_DNS: dns_name } } config_context } } ``` Now the query results in: ```json { "data": null, "errors": [ { "message": "String cannot represent a non string value: {i_contains: $mac_vendor}", "locations": [ { "line": 6, "column": 43 } ] } ] } ```
Author
Owner

@arthanson commented on GitHub (Jun 7, 2024):

@cybarox if this is a bug can you please open a new bug report please as this issue is closed.

@arthanson commented on GitHub (Jun 7, 2024): @cybarox if this is a bug can you please open a new bug report please as this issue is closed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9728