The TenantType in GraphQL is missing the contacts property #10917

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

Originally created by @YiPrograms on GitHub (Mar 19, 2025).

Originally assigned to: @YiPrograms on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.2.5

Python Version

3.10

Steps to Reproduce

  1. Create a tenant (assuming ID 1)
  2. Create a contact (assuming with name "John")
  3. Add a contact assignment to the tenant
  4. Execute the GraphQL query:
query {
  tenant(id: 1) {
    contacts {
      contact {
        name
      }
    }
  }
}

Expected Behavior

Query returns:

{
  "data": {
    "tenant": {
      "contacts": [
        {
          "contact": {
            "name": "John"
          }
        }
      ]
    }
  }
}

Observed Behavior

Query returns contacts on TenantType does not exist:

{
  "data": null,
  "errors": [
    {
      "message": "Cannot query field 'contacts' on type 'TenantType'. Did you mean 'comments'?",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ]
    }
  ]
}
Originally created by @YiPrograms on GitHub (Mar 19, 2025). Originally assigned to: @YiPrograms on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.2.5 ### Python Version 3.10 ### Steps to Reproduce 1. Create a tenant (assuming ID 1) 2. Create a contact (assuming with name "John") 3. Add a contact assignment to the tenant 4. Execute the GraphQL query: ```graphql query { tenant(id: 1) { contacts { contact { name } } } } ``` ### Expected Behavior Query returns: ```json { "data": { "tenant": { "contacts": [ { "contact": { "name": "John" } } ] } } } ``` ### Observed Behavior Query returns contacts on TenantType does not exist: ```json { "data": null, "errors": [ { "message": "Cannot query field 'contacts' on type 'TenantType'. Did you mean 'comments'?", "locations": [ { "line": 3, "column": 5 } ] } ] } ```
adam added the type: bugstatus: acceptedtopic: GraphQLseverity: low labels 2025-12-29 21:37:40 +01:00
adam closed this issue 2025-12-29 21:37:41 +01:00
Author
Owner

@YiPrograms commented on GitHub (Mar 19, 2025):

Similar to #15347, TenantType does not include the ContactMixin.
This can be simply fixed by applying the patch:

diff --git a/netbox/tenancy/graphql/types.py b/netbox/tenancy/graphql/types.py
index 7baa136b3..b07a14c80 100644
--- a/netbox/tenancy/graphql/types.py
+++ b/netbox/tenancy/graphql/types.py
@@ -3,7 +3,7 @@ from typing import Annotated, List
 import strawberry
 import strawberry_django
 
-from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
+from extras.graphql.mixins import CustomFieldsMixin, TagsMixin, ContactsMixin
 from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType
 from tenancy import models
 from .mixins import ContactAssignmentsMixin
@@ -28,7 +28,7 @@ __all__ = (
     fields='__all__',
     filters=TenantFilter
 )
-class TenantType(NetBoxObjectType):
+class TenantType(ContactsMixin, NetBoxObjectType):
     group: Annotated["TenantGroupType", strawberry.lazy('tenancy.graphql.types')] | None
 
     asns: List[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]]

There may be other types that are also missing the ContactMixin. Maybe we should check to ensure all necessary types correctly include it.

@YiPrograms commented on GitHub (Mar 19, 2025): Similar to #15347, `TenantType` does not include the `ContactMixin`. This can be simply fixed by applying the patch: ```diff diff --git a/netbox/tenancy/graphql/types.py b/netbox/tenancy/graphql/types.py index 7baa136b3..b07a14c80 100644 --- a/netbox/tenancy/graphql/types.py +++ b/netbox/tenancy/graphql/types.py @@ -3,7 +3,7 @@ from typing import Annotated, List import strawberry import strawberry_django -from extras.graphql.mixins import CustomFieldsMixin, TagsMixin +from extras.graphql.mixins import CustomFieldsMixin, TagsMixin, ContactsMixin from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType from tenancy import models from .mixins import ContactAssignmentsMixin @@ -28,7 +28,7 @@ __all__ = ( fields='__all__', filters=TenantFilter ) -class TenantType(NetBoxObjectType): +class TenantType(ContactsMixin, NetBoxObjectType): group: Annotated["TenantGroupType", strawberry.lazy('tenancy.graphql.types')] | None asns: List[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]] ``` There may be other types that are also missing the `ContactMixin`. Maybe we should check to ensure all necessary types correctly include it.
Author
Owner

@YiPrograms commented on GitHub (Mar 21, 2025):

I would like to volunteer for this issue.

I've added missing ContactMixin for all the types that has ContactMixin in models/ but not in graphql/types.py.
3466a06ea5

@YiPrograms commented on GitHub (Mar 21, 2025): I would like to volunteer for this issue. I've added missing `ContactMixin` for all the types that has `ContactMixin` in `models/` but not in `graphql/types.py`. https://github.com/YiPrograms/netbox/commit/3466a06ea59f1b033341620c995cd61bc765a268
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10917