NoExtraFieldsForViewSetMixin
Overview
Mixin for DRF ViewSets that raises a VuedaValidationError (400) for any query parameter list or retrieve does not recognize.
list recognizes filterset fields (from filterset_class, when declared) plus pagination, ordering, search, column totals, and REST Flex Fields params (get_extra_allowed_fields()). A viewset with no filterset_class recognizes only the latter set. retrieve recognizes only the expand, fields and omit params -- column totals are a list concept, so the totals param is rejected there.
get_extra_allowed_fields
The query parameters list recognizes beyond this viewset's filterset fields.
The totals parameter is among them only when something on this viewset reads it. It is ListRowLevelViewSetMixin.list that validates the names it carries and answers 400 for an undeclared one, so on a viewset without that mixin recognizing the parameter would mean accepting any value for it and doing nothing, which is the one thing this mixin exists to prevent.
The test is whether the mixin is present, not whether list actually reaches it. A subclass that overrides list and never delegates still recognizes the parameter and then ignores it. That case is left alone deliberately: an override calling super().list() is ordinary and does read the parameter, and nothing here can tell the two apart.
Signature
get_extra_allowed_fields(self)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/core/viewsets/__init__.py:1284
get_retrieve_allowed_fields
Signature
get_retrieve_allowed_fields()
Source
server/vueda/core/viewsets/__init__.py:1312
list
Signature
list(self, request, args, kwargs)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| request | yes | |||
| args | no | |||
| kwargs | no |
Source
server/vueda/core/viewsets/__init__.py:1411
reject_unrecognized_query_params
Signature
reject_unrecognized_query_params(request, valid_fields, message_fields)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| request | yes | |||
| valid_fields | yes | |||
| message_fields | no | None |
Source
server/vueda/core/viewsets/__init__.py:1320
retrieve
Signature
retrieve(self, request, args, kwargs)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| request | yes | |||
| args | no | |||
| kwargs | no |
Source
server/vueda/core/viewsets/__init__.py:1402
validate_flex_expand_and_field_param
Reject each f and e value the serializer cannot render or expand.
list, retrieve, create, and update (which partial_update calls) run this check. A write runs it before the body is validated, so a rejected request saves nothing.
Every invalid name in both parameters goes into one error, keyed by the name. A name invalid in both parameters carries both messages.
:param request: The request whose f and e query values are checked. :param serializer: The action's serializer, built with the action's serializer context. It is the serializer that renders the response. :raises VuedaValidationError: When an f value is not a valid field or wildcard, or an e value is not a permitted expand or wildcard.
Signature
validate_flex_expand_and_field_param(request, serializer)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| request | yes | |||
| serializer | yes |
Source
server/vueda/core/viewsets/__init__.py:1333
Source
server/vueda/core/viewsets/__init__.py:1272