marshmallow-code/marshmallow

Allow None for a allow_none=True Date field

sanketatadvisor opened this issue · 6 comments

Hello,

I have a field called closedDate that could be set as None for a patch operation
image

However, I end up getting openapi validation error for this -
image

The input for this patch operation is {"closedDate": null}

How do ignore/skip validation on a None field?

That field definition appears to correctly allow None. The relevant error message would be at the bottom of the traceback, but it is cutoff. Pasting the error in a markdown code block is generally preferred to screenshots.

{
  "errors": [
    {
      "type": "GENERAL_OPENAPI_VALIDATION_ERROR",
      "title": "Request body validation error",
      "additionalInfo": {
        "traceback": [
          "Traceback (most recent call last):",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/validation/decorators.py\", line 31, in wrapper",
          "    return f(*args, **kwds)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/validation/request/validators.py\", line 253, in _get_body",
          "    return self._get_content_value(raw_body, mimetype, content)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/unmarshallers.py\", line 113, in _get_content_value",
          "    return self._unmarshal_schema(schema, casted)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/unmarshallers.py\", line 90, in _unmarshal_schema",
          "    return unmarshaller.unmarshal(value)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 296, in unmarshal",
          "    typed = type_unmarshaller(value)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 44, in __call__",
          "    return list(map(self.items_unmarshaller.unmarshal, value))",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 296, in unmarshal",
          "    typed = type_unmarshaller(value)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 57, in __call__",
          "    properties = self._unmarshal_properties(value)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 111, in _unmarshal_properties",
          "    properties[prop_name] = self.schema_unmarshaller.evolve(",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 296, in unmarshal",
          "    typed = type_unmarshaller(value)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 145, in __call__",
          "    unmarshaller = self._get_best_unmarshaller(value)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py\", line 166, in _get_best_unmarshaller",
          "    raise UnmarshallerError(\"Unmarshaller not found for type(s)\")",
          "openapi_core.unmarshalling.schemas.exceptions.UnmarshallerError: Unmarshaller not found for type(s)",
          "",
          "The above exception was the direct cause of the following exception:",
          "",
          "Traceback (most recent call last):",
          "  File \"falcon/app.py\", line 327, in falcon.app.App.__call__",
          "  File \"/a360/shared/a360_shared/api/middleware/schema_validation.py\", line 45, in process_request",
          "    results = validate_request(request=openapi_request, spec=core_spec,",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/shortcuts.py\", line 326, in validate_request",
          "    return unmarshal_request(",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/shortcuts.py\", line 173, in unmarshal_request",
          "    return unmarshal_apicall_request(",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/shortcuts.py\", line 117, in unmarshal_apicall_request",
          "    result.raise_for_errors()",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/datatypes.py\", line 14, in raise_for_errors",
          "    raise error",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/unmarshalling/request/unmarshallers.py\", line 154, in _unmarshal",
          "    body = self._get_body(request.body, request.mimetype, operation)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/validation/decorators.py\", line 35, in wrapper",
          "    self._raise_error(exc, self.err_cls, f, *args, **kwds)",
          "  File \"/usr/local/lib/python3.9/site-packages/openapi_core/validation/decorators.py\", line 58, in _raise_error",
          "    raise init(**kw) from exc",
          "openapi_core.validation.request.exceptions.RequestBodyValidationError: Request body validation error"
        ]
      }
    }
  ]
}

Sorry about that. Hope this helps! Correct, None is allowed, so I sent a payload with value as None, I would expect that to not give me a validation error.

Are you using apispec to generate your OpenAPI spec?

yes, I am

This sounds like it might be related to marshmallow-code/apispec#833. Have you upgraded to apispec==6.6.1?

Very interesting!!

I do have the latest one
image