You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
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
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
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
Environment
Steps to Reproduce
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 unlessexclude=config_context
param is provided.Looking at the code in
DeviceViewSet
we returnDeviceWithConfigContextSerializer
by default, unlessconfig_context
is inexclude
params.DeviceWithConfigContextSerializer
subclassesDeviceSerializer
but it overrides itsMeta
class and I can see thatcomputed_fields
key infields
, and alsoopt_in_fields = ["computed_fields"]
are not included inDeviceWithConfigContextSerializer
.As a result
opt_in_fields=computed_fields
params has no effect for devices when querying via API, unless it's combined withexclude=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. whenDeviceWithConfigContextSerializer
is used).The text was updated successfully, but these errors were encountered: