8000 GitHub · Where software is built
[go: up one dir, main page]

Skip to content
Cython Packer requires datetime tzinfo, Python fallback does not #435
Closed
@paolieri

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.
55C7
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.

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

      0