GraphQL filter location list by contacts #11573

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

Originally created by @llamafilm on GitHub (Sep 4, 2025).

Originally assigned to: @llamafilm on GitHub.

NetBox version

v4.3.2

Feature type

New functionality

Proposed functionality

Using GraphQL, I would like to be able to filter the location_list by assigned contacts. For example:

{
  location_list(
    filters:{
      site: {name: {exact:"LA-LAI"}}
      contacts: {name: {exact:"MSE"}}
    }) {
    id
  }
}

This query fails with error

Unsupported lookup 'name__exact' for GenericRel or join on the field not permitted.

Use case

We use contacts to define which team is responsible for supporting each location. I want to build a Grafana dashboard to visualize how many rooms are supported by each team.

Database changes

No response

External dependencies

No response

Originally created by @llamafilm on GitHub (Sep 4, 2025). Originally assigned to: @llamafilm on GitHub. ### NetBox version v4.3.2 ### Feature type New functionality ### Proposed functionality Using GraphQL, I would like to be able to filter the `location_list` by assigned contacts. For example: ``` { location_list( filters:{ site: {name: {exact:"LA-LAI"}} contacts: {name: {exact:"MSE"}} }) { id } } ``` This query fails with error > Unsupported lookup 'name__exact' for GenericRel or join on the field not permitted. ### Use case We use contacts to define which team is responsible for supporting each location. I want to build a Grafana dashboard to visualize how many rooms are supported by each team. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:47:01 +01:00
adam closed this issue 2025-12-29 21:47:01 +01:00
Author
Owner

@llamafilm commented on GitHub (Sep 6, 2025):

I see ContactFilterMixin is already defined so I guess this was intended to work, but it doesn't. I volunteer to fix it.

@llamafilm commented on GitHub (Sep 6, 2025): I see `ContactFilterMixin` is already defined so I guess this was intended to work, but it doesn't. I volunteer to fix it.
Author
Owner

@jeremystretch commented on GitHub (Sep 19, 2025):

I'm reclassifying this as a bug, because the current filter definition for contacts is incorrect as pointed out by @llamafilm here. The filter exists but does not function as expected:

{
  site_list(
    filters:{
      contacts: {
        name: {
          exact: "Dwight Schrute"
        }
      }
    }
  ) {
    name
  }
}

The above GraphQL query yields the following error:

{
  "data": null,
  "errors": [
    {
      "message": "Unsupported lookup 'name__exact' for GenericRel or join on the field not permitted.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "site_list"
      ]
    }
  ]
}

The error indicates that the filter is applied to the generic relation to ContactAssignment, rather than to the Contact itself. With the change proposed in PR #20288, the query can be adapted as follows:

{
  site_list(
    filters:{
      contacts: {
        contact: {
          name: {
            exact: "Dwight Schrute"
          }
        }
      }
    }
  ) {
    name
  }
}

This returns the expected result:

{
  "data": {
    "site_list": [
      {
        "name": "DM-Scranton"
      }
    ]
  }
}
@jeremystretch commented on GitHub (Sep 19, 2025): I'm reclassifying this as a bug, because the current filter definition for `contacts` is incorrect as pointed out by @llamafilm [here](https://github.com/netbox-community/netbox/pull/20288#issuecomment-3301329073). The filter exists but does not function as expected: ```graphql { site_list( filters:{ contacts: { name: { exact: "Dwight Schrute" } } } ) { name } } ``` The above GraphQL query yields the following error: ```json { "data": null, "errors": [ { "message": "Unsupported lookup 'name__exact' for GenericRel or join on the field not permitted.", "locations": [ { "line": 2, "column": 3 } ], "path": [ "site_list" ] } ] } ``` The error indicates that the filter is applied to the generic relation to ContactAssignment, rather than to the Contact itself. With the change proposed in PR #20288, the query can be adapted as follows: ```graphql { site_list( filters:{ contacts: { contact: { name: { exact: "Dwight Schrute" } } } } ) { name } } ``` This returns the expected result: ```json { "data": { "site_list": [ { "name": "DM-Scranton" } ] } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11573