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

computed_fields key not included in API response for devices when using opt_in_fields - v1.1.0b1 #661

Closed
progala opened this issue Jul 8, 2021 · 1 comment · Fixed by #664
Labels
type: bug Something isn't working as expected

Comments

@progala
Copy link

progala commented Jul 8, 2021

Environment

  • Python version: Python 3.8.7
  • Nautobot version: v1.1.0b1

Steps to Reproduce

  1. Retrieve device object(s) via API call including opt_in_fields=computed_fields

E.g.

http://172.27.145.233:8080/api/dcim/devices/?opt_in_fields=computed_fields&name=ams-edge-01

Expected Behavior

computed_fields key is included in the API response.

Observed Behavior

computed_fields key is missing in the API response.

Details

I've been testing computed fields feature in Nautobot v1.1.0b1. When I ask to include computed_fields for devices via API, the key computed_fields is missing in the payload unless exclude=config_context param is provided.

Looking at the code in DeviceViewSet we return DeviceWithConfigContextSerializer by default, unless config_context is in exclude params.

        elif "config_context" in request.query_params.get("exclude", []):
            return serializers.DeviceSerializer

        return serializers.DeviceWithConfigContextSerializer

DeviceWithConfigContextSerializer subclasses DeviceSerializer but it overrides its Meta class and I can see that computed_fields key in fields, and also opt_in_fields = ["computed_fields"] are not included in DeviceWithConfigContextSerializer.

As a result opt_in_fields=computed_fields params has no effect for devices when querying via API, unless it's combined with exclude=config_context

I don't know if this is intended but I would expect the computed_fields to be included in the API response for the default case (i.e. when DeviceWithConfigContextSerializer is used).

@progala progala changed the title custom_fields key not included in API response for devices when using opt_in_fields custom_fields key not included in API response for devices when using opt_in_fields - v1.1.0 Jul 8, 2021
@progala progala changed the title custom_fields key not included in API response for devices when using opt_in_fields - v1.1.0 custom_fields key not included in API response for devices when using opt_in_fields - v1.1.0b1 Jul 8, 2021
@progala progala changed the title custom_fields key not included in API response for devices when using opt_in_fields - v1.1.0b1 computed_fields key not included in API response for devices when using opt_in_fields - v1.1.0b1 Jul 8, 2021
@jedelman8 jedelman8 added status: accepted type: bug Something isn't working as expected and removed status: accepted labels Jul 8, 2021
@jfach
Copy link
Contributor

jfach commented Jul 8, 2021

I'll take this one.

jathanism added a commit that referenced this issue Jul 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants