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

Allow None for a allow_none=True Date field #2266

Open
sanketatadvisor opened this issue May 13, 2024 · 6 comments
Open

Allow None for a allow_none=True Date field #2266

sanketatadvisor opened this issue May 13, 2024 · 6 comments
Labels

Comments

@sanketatadvisor
Copy link

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?

@sanketatadvisor sanketatadvisor changed the title Allow None for a allow_none=True field in patch Allow None for a allow_none=True Date field May 13, 2024
@deckar01
Copy link
Member

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.

@sanketatadvisor
Copy link
Author

{
  "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.

@deckar01
Copy link
Member

Are you using apispec to generate your OpenAPI spec?

@sanketatadvisor
Copy link
Author

yes, I am

@deckar01
Copy link
Member

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

@sanketatadvisor
Copy link
Author

Very interesting!!

I do have the latest one
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants