Skip to content

Conversation

lazyhope
Copy link
Contributor

@lazyhope lazyhope commented Jun 25, 2024

Change Summary

This PR adds a new constant DECIMAL_CONSTRAINTS into pydantic/_internal/_known_annotated_metadata.py, allowing field constraints to be automatically applied to the inner Decimal types of an Optional[Decimal] type, e.g. Annotated[Decimal | None, Field(max_digits=3)].

Related issue number

fix #9748
and other related issues

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @adriangb

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Jun 25, 2024
Copy link

codspeed-hq bot commented Jun 25, 2024

CodSpeed Performance Report

Merging #9754 will not alter performance

Comparing lazyhope:allow-optional-decimal-constraints (f05f847) with main (baf4edc)

Summary

✅ 13 untouched benchmarks

@lazyhope
Copy link
Contributor Author

The PR is ready, @sydney-runkle please review, thanks a lot!

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Great! Simple fix, and makes things easier for users. Thanks a bunch!

@sydney-runkle sydney-runkle enabled auto-merge (squash) June 25, 2024 14:33
@sydney-runkle sydney-runkle merged commit f024d03 into pydantic:main Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistency handling constraints for Optional[decimal.Decimal] and other optional "primitive" types
3 participants