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

autotype_decorator fails on annotated fields #15532

Closed
arthanson opened this issue Mar 26, 2024 · 2 comments
Closed

autotype_decorator fails on annotated fields #15532

arthanson opened this issue Mar 26, 2024 · 2 comments
Assignees
Labels
beta Concerns a bug/feature in a beta release severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@arthanson
Copy link
Collaborator

Deployment Type

Self-hosted

NetBox Version

v4.0

Python Version

3.8

Steps to Reproduce

  1. Create an annotated field for a model
  2. Add it to the filterset for the model
  3. Use the autotype_decorator for the filterset

Run into by peteeckel when migrating the DNS plugin to NB 4

For example:

Definition of the annotation:

    def get_queryset(self):
        return (
            super()
            .get_queryset()
            .annotate(
                active=ExpressionWrapper(
                    Q(status__in=Zone.ACTIVE_STATUS_LIST), output_field=BooleanField()
                )
            )
        )

Definition in the filterset:

    active = django_filters.BooleanFilter(
        label="Zone is active",
    )

Expected Behavior

autotype_decorator should not throw an error

Observed Behavior

autotype_decorator throws a FieldDoesNotExist error.

@arthanson arthanson added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Mar 26, 2024
@arthanson arthanson self-assigned this Mar 26, 2024
@peteeckel
Copy link
Contributor

I'm not sure a fix is necessary after all, at least not for the annotation I added.

After removing the decorator from fields and just leaving a BooleanFilter for the annotated field in place, the @autotype_decorator created a functional filter without any further measures:

$ curl -s -H "Authorization: Token xxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -H "Accept: application/json"  https://netbox.example.com/graphql/ --data '{"query": "query {netbox_dns_zone_list(filters: {active: false}) {view {name}, name, status, active}}" }' | json_pp
{
   "data" : {
      "netbox_dns_zone_list" : [
         {
            "active" : false,
            "name" : "zone13.example.com",
            "status" : "reserved",
            "view" : null
         }
      ]
   }
}

So after removing the annotation from fields all seems to be OK.

@jeremystretch
Copy link
Member

@arthanson can you confirm the above? And if not, could you please assign a severity to the bug?

@arthanson arthanson added beta Concerns a bug/feature in a beta release severity: low Does not significantly disrupt application functionality, or a workaround is available labels Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Concerns a bug/feature in a beta release severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants