haystack icon indicating copy to clipboard operation
haystack copied to clipboard

bug: handle `Optional` params in schema validation

Open anakin87 opened this issue 2 years ago • 1 comments

Related Issues

  • fixes #2589

Proposed Changes:

First draft to manually temporarily fix this problem. When Pydantic v2 will be released, there will be no need of this fix.

How did you test it?

Included test

Notes for the reviewer

Checklist

anakin87 avatar Aug 06 '22 15:08 anakin87

Notes for the reviewer

In handle_optional_params function:

  • I first find the optional params. This implementation is tested in Python 3.7 and 3.10, even if the annotations management is different in the two versions.
  • for every optional param, the schema is updated using anyOf and {"type": "null"}. I don't like very much this part and I also tried to monkey patch the Pydantic schema generation, but it seemed too intricate.

The test tries to load a pipeline, with a null parameter. This test was failing with the current JSON schema.

anakin87 avatar Aug 08 '22 10:08 anakin87

Great timing @ZanSara and @anakin87 - I need this PR for https://github.com/deepset-ai/haystack/pull/3062

vblagoje avatar Aug 18 '22 20:08 vblagoje