autotype_decorator fails on annotated fields #9389

Closed
opened 2025-12-29 20:49:13 +01:00 by adam · 2 comments
Owner

Originally created by @arthanson on GitHub (Mar 26, 2024).

Originally assigned to: @arthanson on GitHub.

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.

Originally created by @arthanson on GitHub (Mar 26, 2024). Originally assigned to: @arthanson on GitHub. ### 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.
adam added the type: bugstatus: acceptedbetaseverity: low labels 2025-12-29 20:49:13 +01:00
adam closed this issue 2025-12-29 20:49:13 +01:00
Author
Owner

@peteeckel commented on GitHub (Mar 26, 2024):

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.

@peteeckel commented on GitHub (Mar 26, 2024): 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.
Author
Owner

@jeremystretch commented on GitHub (Apr 3, 2024):

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

@jeremystretch commented on GitHub (Apr 3, 2024): @arthanson can you confirm the above? And if not, could you please assign a severity to the bug?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9389