pydantic / pydantic-core

Core validation logic for pydantic written in rust
MIT License
1.34k stars 207 forks source link

Add list fail-fast config option #1322

Closed uriyyo closed 1 week ago

uriyyo commented 1 month ago

Change Summary

Add list fail-fast config option.

Related issue number

fix: #1321

Checklist

Selected Reviewer: @dmontagu

uriyyo commented 1 month ago

please review

codspeed-hq[bot] commented 1 month ago

CodSpeed Performance Report

Merging #1322 will not alter performance

Comparing uriyyo:list-fail-fast (27db075) with main (9507a28)

Summary

✅ 155 untouched benchmarks

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 92.85714% with 3 lines in your changes missing coverage. Please review. Files Patch % Lines
src/validators/tuple.rs 86.36% 3 Missing :warning:

:loudspeaker: Thoughts on this report? Let us know!

uriyyo commented 3 weeks ago

Great, I will update this PR to add this feature to more iterable types!

adriangb commented 3 weeks ago

Could we implement this as an exception, similar to PydanticOmit? That way a python-defined validator can control the flow.

uriyyo commented 3 weeks ago

@adriangb Makes sense to me, I will try to reimplement it in similar way as PydanticOmit is working

adriangb commented 3 weeks ago

It may be that both are necessary, there's mutliple use cases:

  1. Inside of a python validator you want to abort the rest of the list, similar workflow to PydanticOmit
  2. You just want to abort early with no python handler (like this PR implements)
uriyyo commented 3 weeks ago

Hi @adriangb @davidhewitt

This PR is ready with basic implementation of fail-fast feature for list, set, frozenset, and tuple types.

Could we implement this as an exception, similar to PydanticOmit? That way a python-defined validator can control the flow.

@adriangb I suggest implement this feature in separate PR just to make review/merge process easier. What do you think about it?

adriangb commented 3 weeks ago

Makes sense to me

davidhewitt commented 1 week ago

I see the Python PR is now prepared too, many thanks 🚀