GraphQL CustomFieldChoiceSet erroring on extra_choices #10275

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

Originally created by @gellis713 on GitHub (Sep 20, 2024).

Originally assigned to: @gellis713 on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.1.1

Python Version

3.12

Steps to Reproduce

1: Create a new custom field choice set called "MY_CHOICE_SET" under Customization -> Custom Field Choices. In the "Extra choices" field enter:

A:A
B:B
C:C

2: Try to execute following graphql query from the API or from the web interface. Replace MY_CHOICE_SET with

query {
  custom_field_choice_set_list {
    id
    extra_choices
  }
}

Expected Behavior

Returned JSON:

{
  "data": {
    "custom_field_choice_set_list": [
      {
        "id": "5",
        "extra_choices": [
          [
            "A",
            "A"
          ],
          [
            "B",
            "B"
          ],
          [
            "C",
            "C"
          ]
        ]
      }
    ]
  }
}

Observed Behavior

Returned JSON:

{
  "data": {
    "custom_field_choice_set_list": [
      {
        "id": "5",
        "extra_choices": null
      },
      {
        "id": "1",
        "extra_choices": null
      },
      {
        "id": "2",
        "extra_choices": null
      },
      {
        "id": "3",
        "extra_choices": null
      },
      {
        "id": "4",
        "extra_choices": null
      }
    ]
  },
  "errors": [
    {
      "message": "String cannot represent value: ['A', 'A']",
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "path": [
        "custom_field_choice_set_list",
        0,
        "extra_choices",
        0
      ]
    }
  ]
}
Originally created by @gellis713 on GitHub (Sep 20, 2024). Originally assigned to: @gellis713 on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.1.1 ### Python Version 3.12 ### Steps to Reproduce 1: Create a new custom field choice set called "MY_CHOICE_SET" under Customization -> Custom Field Choices. In the "Extra choices" field enter: ``` A:A B:B C:C ``` 2: Try to execute following graphql query from the API or from the web interface. Replace MY_CHOICE_SET with ``` query { custom_field_choice_set_list { id extra_choices } } ``` ### Expected Behavior Returned JSON: ``` { "data": { "custom_field_choice_set_list": [ { "id": "5", "extra_choices": [ [ "A", "A" ], [ "B", "B" ], [ "C", "C" ] ] } ] } } ``` ### Observed Behavior Returned JSON: ``` { "data": { "custom_field_choice_set_list": [ { "id": "5", "extra_choices": null }, { "id": "1", "extra_choices": null }, { "id": "2", "extra_choices": null }, { "id": "3", "extra_choices": null }, { "id": "4", "extra_choices": null } ] }, "errors": [ { "message": "String cannot represent value: ['A', 'A']", "locations": [ { "line": 4, "column": 5 } ], "path": [ "custom_field_choice_set_list", 0, "extra_choices", 0 ] } ] } ```
adam added the type: bugstatus: accepted labels 2025-12-29 21:29:16 +01:00
adam closed this issue 2025-12-29 21:29:16 +01:00
Author
Owner

@gellis713 commented on GitHub (Sep 20, 2024):

I already have a fix for this issue which is to replace the following in netbox/extras/types.py (note extra_choices should be List[List[str]]

class CustomFieldChoiceSetType(ObjectType):

    choices_for: List[Annotated["CustomFieldType", strawberry.lazy('extras.graphql.types')]]
    extra_choices: List[str] | None

with

class CustomFieldChoiceSetType(ObjectType):

    choices_for: List[Annotated["CustomFieldType", strawberry.lazy('extras.graphql.types')]]
    extra_choices: List[List[str]] | None
@gellis713 commented on GitHub (Sep 20, 2024): I already have a fix for this issue which is to replace the following in netbox/extras/types.py (note extra_choices should be List[List[str]] ``` class CustomFieldChoiceSetType(ObjectType): choices_for: List[Annotated["CustomFieldType", strawberry.lazy('extras.graphql.types')]] extra_choices: List[str] | None ``` with ``` class CustomFieldChoiceSetType(ObjectType): choices_for: List[Annotated["CustomFieldType", strawberry.lazy('extras.graphql.types')]] extra_choices: List[List[str]] | None ```
Author
Owner

@arthanson commented on GitHub (Sep 23, 2024):

@gellis713 Assigning you to the issue as it looks like you have a PR. Note, I was actually getting an error on the GraphQL query:

{
  "data": {
    "custom_field_choice_set_list": [
      {
        "id": "1",
        "extra_choices": null
      }
    ]
  },
  "errors": [
    {
      "message": "String cannot represent value: ['A', 'A']",
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "path": [
        "custom_field_choice_set_list",
        0,
        "extra_choices",
        0
      ]
    }
  ]
}
@arthanson commented on GitHub (Sep 23, 2024): @gellis713 Assigning you to the issue as it looks like you have a PR. Note, I was actually getting an error on the GraphQL query: ``` { "data": { "custom_field_choice_set_list": [ { "id": "1", "extra_choices": null } ] }, "errors": [ { "message": "String cannot represent value: ['A', 'A']", "locations": [ { "line": 4, "column": 5 } ], "path": [ "custom_field_choice_set_list", 0, "extra_choices", 0 ] } ] } ```
Author
Owner

@gellis713 commented on GitHub (Sep 23, 2024):

@arthanson Yes it appears you have the same observed behavior that I posted in the issue report. Glad to see it was reproducible. Is there anything I can/should do while waiting for the PR to be reviewed? Thanks

@gellis713 commented on GitHub (Sep 23, 2024): @arthanson Yes it appears you have the same observed behavior that I posted in the issue report. Glad to see it was reproducible. Is there anything I can/should do while waiting for the PR to be reviewed? Thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10275