Repository: rotki/rotki

Issue:
Unexpected data encountered during deserialization of a bittrex asset movement
## Problem Definition

When generating a tax report I get the following error in the notifications:

`Unexpected data encountered during deserialization of a bittrex asset movement. Check logs for details and open a bug report.
`
From the rotkehlchen.log it seems to be an issue with the bittrex timestamp:

`ERROR:rotkehlchen.exchanges.bittrex:Unexpected data encountered during deserialization of bittrex asset_movement {'Id': 22240499, 'Amount': FVal(9.99532679), 'Currency': 'ETH', 'Confirmations': 37, 'LastUpdated': '2017-07-08T07:57:12', 'TxId': '...', 'CryptoAddress': '.....'}. Error was: Failed to deserialize 2017-07-08T07:57:12 bittrex timestamp entry`

### System Description

```
Linux tux 4.18.0-17-generic #18~18.04.1-Ubuntu SMP Fri Mar 15 15:27:12 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Rotki 1.5.0
```



Discussion:
Hey @davbre thank you for making the issue and providing relevant logs. I will have a look.

Resolving patch:
diff --git a/rotkehlchen/serialization/deserialize.py b/rotkehlchen/serialization/deserialize.py
--- a/rotkehlchen/serialization/deserialize.py
+++ b/rotkehlchen/serialization/deserialize.py
@@ -85,7 +85,11 @@ def deserialize_timestamp(timestamp: Union[int, str, FVal]) -> Timestamp:
     return processed_timestamp
 
 
-def deserialize_timestamp_from_date(date: str, formatstr: str, location: str) -> Timestamp:
+def deserialize_timestamp_from_date(
+        date: Optional[str],
+        formatstr: str,
+        location: str,
+) -> Timestamp:
     """Deserializes a timestamp from a date entry depending on the format str
 
     formatstr can also have a special value of 'iso8601' in which case the iso8601
@@ -124,7 +128,7 @@ def deserialize_timestamp_from_poloniex_date(date: str) -> Timestamp:
     return deserialize_timestamp_from_date(date, '%Y-%m-%d %H:%M:%S', 'poloniex')
 
 
-def deserialize_timestamp_from_bittrex_date(date: str) -> Timestamp:
+def deserialize_timestamp_from_bittrex_date(date: Optional[str]) -> Timestamp:
     """Deserializes a timestamp from a bittrex api query result date entry
 
     Bittrex trades follow the given format and unfortunately
@@ -133,6 +137,9 @@ def deserialize_timestamp_from_bittrex_date(date: str) -> Timestamp:
 
     Can throw DeserializationError if the data is not as expected
     """
+    # Some dates have milliseconds, some not. Add 0 milliseconds for this to work
+    if date is not None and '.' not in date:
+        date += '.0'
     return deserialize_timestamp_from_date(date, '%Y-%m-%dT%H:%M:%S.%f', 'bittrex')
 
 


Test patch:
diff --git a/rotkehlchen/tests/exchanges/test_bittrex.py b/rotkehlchen/tests/exchanges/test_bittrex.py
--- a/rotkehlchen/tests/exchanges/test_bittrex.py
+++ b/rotkehlchen/tests/exchanges/test_bittrex.py
@@ -9,11 +9,24 @@
 from rotkehlchen.exchanges.bittrex import Bittrex
 from rotkehlchen.exchanges.data_structures import Trade
 from rotkehlchen.fval import FVal
+from rotkehlchen.serialization.deserialize import deserialize_timestamp_from_bittrex_date
 from rotkehlchen.tests.utils.history import TEST_END_TS
 from rotkehlchen.tests.utils.mock import MockResponse
 from rotkehlchen.typing import AssetMovementCategory, Location, TradeType
 
 
+def test_deserialize_timestamp_from_bittrex_date():
+    """Test for deserialize_timestamp_from_bittrex_date() and regression for #1151
+
+    In https://github.com/rotki/rotki/issues/1151 a user encountered an error with
+    the following date: 2017-07-08T07:57:12
+    """
+    assert deserialize_timestamp_from_bittrex_date('2014-02-13T00:00:00.00') == 1392249600
+    assert deserialize_timestamp_from_bittrex_date('2015-06-15T07:38:53.883') == 1434353933
+    assert deserialize_timestamp_from_bittrex_date('2015-08-19T04:24:47.217') == 1439958287
+    assert deserialize_timestamp_from_bittrex_date('2017-07-08T07:57:12') == 1499500632
+
+
 def test_name():
     exchange = Bittrex('a', b'a', object(), object())
     assert exchange.name == 'bittrex'