Skip to content

Nicer error when packing a datetime without tzinfo #466

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

Merged
merged 3 commits into from
Nov 16, 2021

Conversation

begelundmuller
Copy link
Contributor

When attempting to pack a datetime.datetime object with msgpack.packb(dt, datetime=True) where the dt object is missing tzinfo, the library throws the generic error TypeError: can not serialize 'datetime.datetime' object.

That threw me off as I thought the problem related to datetime=True, and didn't realise I was missing tzinfo. This small patch outputs a more specific error message for that edge case.

@codecov-io
Copy link

codecov-io commented Feb 26, 2021

Codecov Report

Merging #466 (d845b65) into main (4ace82f) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #466      +/-   ##
==========================================
+ Coverage   87.80%   87.84%   +0.03%     
==========================================
  Files           5        5              
  Lines         730      732       +2     
==========================================
+ Hits          641      643       +2     
  Misses         89       89              
Impacted Files Coverage Δ
msgpack/fallback.py 88.85% <100.00%> (+0.03%) ⬆️

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 4ace82f...d845b65. Read the comment docs.

@begelundmuller
Copy link
Contributor Author

Addressed your comment in this new commit – it now respects the default function.

The logic is getting a little twisted, though. If you don't think it's worth it for such a minor convenience, I understand.

@methane methane merged commit e464cb4 into msgpack:main Nov 16, 2021
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.

3 participants