Skip to content

Conversation

@dconathan
Copy link
Contributor

See #3790

Basically, Pydantic's schema for the loc field of the error detail is Union[str, int] not str for e.g. cases when the invalid data is at a particular index of an array:

See the type defined in Pydantic's source here:
https://github.com/samuelcolvin/pydantic/blob/5ccbdcb5904f35834300b01432a665c75dc02296/pydantic/error_wrappers.py#L12

The openapi.json schema for a ValidationError should match this.

This is particularly important for automated testing using https://schemathesis.readthedocs.io/en/stable/ because ValidationErrors that don't match the schema will lead to failing tests.

I've updated the validation_error_definition (h/t to @silversurfer34 for creating the issue and supplying the fixed schema 😄 ).
Also I had to update all the tests since the openapi.jsons are hardcoded in that.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 95ce749 at: https://612e50e590ccc9407a6d3a82--fastapi.netlify.app

@codecov
Copy link

codecov bot commented Aug 31, 2021

Codecov Report

Merging #3810 (ae1128a) into master (864643e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #3810   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          409       409           
  Lines        10264     10264           
=========================================
  Hits         10264     10264           
Impacted Files Coverage Δ
fastapi/openapi/utils.py 100.00% <ø> (ø)
tests/test_additional_properties.py 100.00% <ø> (ø)
...t_additional_responses_custom_model_in_callback.py 100.00% <ø> (ø)
...st_additional_responses_default_validationerror.py 100.00% <ø> (ø)
tests/test_application.py 100.00% <ø> (ø)
tests/test_dependency_duplicates.py 100.00% <ø> (ø)
tests/test_extra_routes.py 100.00% <ø> (ø)
tests/test_filter_pydantic_sub_model.py 100.00% <ø> (ø)
tests/test_get_request_body.py 100.00% <ø> (ø)
tests/test_include_router_defaults_overrides.py 100.00% <ø> (ø)
... and 68 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 864643e...ae1128a. Read the comment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 6caac74 at: https://612ea7456baaa23ddbd68c4c--fastapi.netlify.app

Copy link

@silversurfer34 silversurfer34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

📝 Docs preview for commit ae1128a at: https://615f4487606f2867f92c1744--fastapi.netlify.app

@tiangolo tiangolo changed the title Fix validation error loc schema 🐛 Fix JSON Schema for ValidationError at field loc Apr 17, 2022
@tiangolo
Copy link
Member

Awesome, thanks @dconatha for the work and explanation! 🤓 🍰

This will be available in FastAPI 0.75.2, released in a couple of hours. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants