haystack
haystack copied to clipboard
bug: handle `Optional` params in schema validation
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
- [X] I have read the contributors guidelines and the code of conduct
- [ ] I have updated the related issue with new insights and changes
- [X] I added tests that demonstrate the correct behavior of the change
- [X] I've used the conventional commit convention for my PR title
- [X] I documented my code
- [X] I ran pre-commit hooks and fixed any issue
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.
Great timing @ZanSara and @anakin87 - I need this PR for https://github.com/deepset-ai/haystack/pull/3062