Skip to content

Commit 8257b39

Browse files
committed
Fix unpacking of negative timestamps from msgpack
- Update the work of PR influxdata#734 to correctly interpret negative timestamps - Update unit test for pre-unix epoch date with negative timestamp
1 parent fc0235e commit 8257b39

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

influxdb/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ def _parse_netloc(netloc):
12431243

12441244
def _msgpack_parse_hook(code, data):
12451245
if code == 5:
1246-
(epoch_s, epoch_ns) = struct.unpack(">QI", data)
1246+
(epoch_s, epoch_ns) = struct.unpack(">qI", data)
12471247
timestamp = datetime.datetime.utcfromtimestamp(epoch_s)
12481248
timestamp += datetime.timedelta(microseconds=(epoch_ns / 1000))
12491249
return timestamp.isoformat() + 'Z'

influxdb/tests/client_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ def test_query_msgpack(self):
575575
example_response = bytes(bytearray.fromhex(
576576
"81a7726573756c74739182ac73746174656d656e745f696400a673657269"
577577
"65739183a46e616d65a161a7636f6c756d6e7392a474696d65a176a67661"
578-
"6c7565739192c70c05000000005d26178a019096c8cb3ff0000000000000"
578+
"6c7565739292c70c05000000005d26178a019096c8cb3ff0000000000000"
579+
"92c70c05ffffffffffff7360075bcd15cb4000000000000000"
579580
))
580581

581582
with requests_mock.Mocker() as m:
@@ -590,7 +591,7 @@ def test_query_msgpack(self):
590591

591592
self.assertListEqual(
592593
list(rs.get_points()),
593-
[{'v': 1.0, 'time': '2019-07-10T16:51:22.026253Z'}]
594+
[{'v': 1.0, 'time': '2019-07-10T16:51:22.026253Z'}, {'v': 2.0, 'time': '1969-12-31T14:00:00.123457Z'}]
594595
)
595596

596597
def test_select_into_post(self):

0 commit comments

Comments
 (0)