Skip to content

Commit

Permalink
Fix unpacking of negative timestamps from msgpack
Browse files Browse the repository at this point in the history
- Update the work of PR influxdata#734 to correctly interpret negative timestamps
- Update unit test for pre-unix epoch date with negative timestamp
  • Loading branch information
bitoffdev committed Aug 22, 2020
1 parent fc0235e commit 8257b39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,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
5 changes: 3 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"
"92c70c05ffffffffffff7360075bcd15cb4000000000000000"
))

with requests_mock.Mocker() as m:
Expand All @@ -590,7 +591,7 @@ 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-31T14:00:00.123457Z'}]
)

def test_select_into_post(self):
Expand Down

0 comments on commit 8257b39

Please sign in to comment.