Skip to content

Cython Packer requires datetime tzinfo, Python fallback does not #435

Closed

Description

@paolieri

With msgpack 1.0.0, this works:

import msgpack
from msgpack.fallback import Packer
import datetime

dt = datetime.datetime(2020, 7, 24, 0, 37, 28, 190432,
                       tzinfo=datetime.timezone.utc)

packed = Packer(datetime=True).pack(dt)
print(msgpack.unpackb(packed, timestamp=3))

packed = msgpack.Packer(datetime=True).pack(dt)
print(msgpack.unpackb(packed, timestamp=3))

But, without tzinfo, the Cython version fails:

import msgpack
from msgpack.fallback import Packer
import datetime

dt = datetime.datetime(2020, 7, 24, 0, 37, 28, 190432)

packed = Packer(datetime=True).pack(dt)
print(msgpack.unpackb(packed, timestamp=3))

packed = msgpack.Packer(datetime=True).pack(dt)
print(msgpack.unpackb(packed, timestamp=3))
2020-07-24 07:37:28.190432+00:00
Traceback (most recent call last):
  File "test_msgpack.py", line 10, in <module>
    packed = msgpack.Packer(datetime=True).pack(dt)
  File "msgpack/_packer.pyx", line 286, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 292, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 289, in msgpack._cmsgpack.Packer.pack
  File "msgpack/_packer.pyx", line 283, in msgpack._cmsgpack.Packer._pack
TypeError: can not serialize 'datetime.datetime' object

Should we make the Python fallback implementation stricter? I can create a PR.

Activity

  1. methane commented on Jul 24, 2020

    @methane
    Member

    Fixed via #434.

  2. paolieri commented on Jul 24, 2020

    @paolieri
    Author

    Thank you! (So fast.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions