Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8570]fix: raise exception for years less than 1600 #55

Closed
wants to merge 1 commit into from

Conversation

StrawHatDrag0n
Copy link

Copy link

codecov bot commented Jan 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.13%. Comparing base (ef53708) to head (025d840).
Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #55   +/-   ##
=======================================
  Coverage   99.12%   99.13%           
=======================================
  Files           6        6           
  Lines         918      922    +4     
=======================================
+ Hits          910      914    +4     
  Misses          8        8           
Files with missing lines Coverage Δ
src/date.rs 100.00% <100.00%> (ø)
src/lib.rs 91.66% <ø> (ø)

Continue to review full report in Codecov by Sentry.

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

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

I'm afraid I don't agree with this change, nor the suggestion that raising a more informative error is the correct fix.

I think most likely the source of the panic is on the following line, where year is a u16 so subtracting 1600 from it is incorrect for years under 1600

let days = (self.year - 1600) as i64 * 365

Probably it would be more correct as (self.year as i64 - 1600) * 365, as i64 can go below 0.

There's a slight follow up question of what the limits of that timestamp() function would be, probably operations in that function which we think can overflow should use .checked_mul() / .checked_sub()

Comment on lines +333 to +336
if year < 1600 {
return Err(ParseError::YearTooSmall);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this here will break pydantic's ability to parse all dates before 1600, whereas currently the issue only exists for FutureDatetime (and I guess PastDatetime).

@davidhewitt
Copy link
Contributor

Superseded by #77

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.

FutureDatetime accepts years 1000-1599
2 participants