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

better error message for TypeError on datetime parsing #766

Merged
merged 3 commits into from Aug 21, 2019

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Aug 18, 2019

Change Summary

While working on #763 I discovered that we had no tests and ugly errors if anything other than a native datetime/date/time/timedelta, string, int or float was passed to those parsers.

Changes:

  • fix the above - more descriptive error message
  • add support for bytes by decoding them before regex matching
  • change invalid values to be value_errors not type_errors - more correct.

Github doesn't do a very good job of showing it, but this change is mainly just an indentation change plus adding if isinstance(value, bytes): value = value.decode().

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.rst file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Aug 21, 2019

Codecov Report

Merging #766 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #766   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines        2734   2747   +13     
  Branches      541    546    +5     
=====================================
+ Hits         2734   2747   +13
Impacted Files Coverage Δ
pydantic/errors.py 100% <100%> (ø) ⬆️
pydantic/datetime_parse.py 100% <100%> (ø) ⬆️

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 0e8cfba...74c597a. Read the comment docs.

@samuelcolvin samuelcolvin merged commit 9dee83a into master Aug 21, 2019
@samuelcolvin samuelcolvin deleted the datetime-type-errors branch August 21, 2019 12:45
alexdrydew pushed a commit to alexdrydew/pydantic that referenced this pull request Dec 23, 2023
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.

None yet

1 participant