Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Fix unpacking of negative timestamps from msgpack #846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ def _parse_netloc(netloc):

def _msgpack_parse_hook(code, data):
if code == 5:
(epoch_s, epoch_ns) = struct.unpack(">QI", data)
(epoch_s, epoch_ns) = struct.unpack(">qi", data)
timestamp = datetime.datetime.utcfromtimestamp(epoch_s)
timestamp += datetime.timedelta(microseconds=(epoch_ns / 1000))
return timestamp.isoformat() + 'Z'
Expand Down
8 changes: 6 additions & 2 deletions influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ def test_query_msgpack(self):
example_response = bytes(bytearray.fromhex(
"81a7726573756c74739182ac73746174656d656e745f696400a673657269"
"65739183a46e616d65a161a7636f6c756d6e7392a474696d65a176a67661"
"6c7565739192c70c05000000005d26178a019096c8cb3ff0000000000000"
"6c7565739292c70c05000000005d26178a019096c8cb3ff0000000000000"
"92c70c05fffffffffffee6c0ff439eb2cb4000000000000000"
))

with requests_mock.Mocker() as m:
Expand All @@ -590,7 +591,10 @@ def test_query_msgpack(self):

self.assertListEqual(
list(rs.get_points()),
[{'v': 1.0, 'time': '2019-07-10T16:51:22.026253Z'}]
[
{"v": 1.0, "time": "2019-07-10T16:51:22.026253Z"},
{"v": 2.0, "time": "1969-12-31T03:59:59.987654Z"},
],
)

def test_select_into_post(self):
Expand Down