From fa1e7e7ebe5c2fee48b74b0b6adeafe9ff6ff755 Mon Sep 17 00:00:00 2001 From: Elliot Miller Date: Sun, 23 Aug 2020 16:46:50 -0400 Subject: [PATCH] Fix unpacking of negative timestamps from msgpack --- influxdb/client.py | 2 +- influxdb/tests/client_test.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 51a64ac3..bd71b4a6 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -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' diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index e511ca9b..b754a043 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -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: @@ -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):