Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL CustomFieldChoiceSet erroring on extra_choices #17562

Open
gellis713 opened this issue Sep 20, 2024 · 3 comments · May be fixed by #17563
Open

GraphQL CustomFieldChoiceSet erroring on extra_choices #17562

gellis713 opened this issue Sep 20, 2024 · 3 comments · May be fixed by #17563
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@gellis713
Copy link

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
      ]
    }
  ]
}
@gellis713 gellis713 added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Sep 20, 2024
@gellis713
Copy link
Author

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 gellis713 linked a pull request Sep 20, 2024 that will close this issue
@arthanson arthanson added status: accepted This issue has been accepted for implementation and removed status: needs triage This issue is awaiting triage by a maintainer labels Sep 23, 2024
@arthanson
Copy link
Collaborator

@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
      ]
    }
  ]
}

@gellis713
Copy link
Author

@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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants