Repository: rotki/rotki

Issue:
Exception in query all balances
## Problem Definition

Saw this in a user's logs:

```
[07/01/2021 12:43:26 CET] INFO rotkehlchen.api.server.pywsgi: 127.0.0.1 - - "GET /api/1/tasks/ HTTP/1.1" 200 251 0.002538
[07/01/2021 12:43:27 CET] ERROR rotkehlchen.api.rest: Greenlet for task 1 dies with exception: 'Balance' object is not subscriptable.
Exception Name: <class 'TypeError'>
Exception Info: 'Balance' object is not subscriptable
Traceback:
   File "src/gevent/greenlet.py", line 818, in gevent._greenlet.Greenlet.run
  File "rotkehlchen/api/rest.py", line 241, in _do_query_async
  File "rotkehlchen/api/rest.py", line 365, in _query_all_balances
  File "rotkehlchen/rotkehlchen.py", line 723, in query_balances
  File "rotkehlchen/utils/misc.py", line 157, in combine_stat_dicts
  File "rotkehlchen/utils/misc.py", line 140, in combine_dicts
  File "rotkehlchen/utils/misc.py", line 140, in <listcomp>
  File "rotkehlchen/utils/misc.py", line 146, in _add_entries
```
Figure out why this would happen and fix it.

## Task

Fix it


Discussion:

Resolving patch:
diff --git a/rotkehlchen/exchanges/bitfinex.py b/rotkehlchen/exchanges/bitfinex.py
--- a/rotkehlchen/exchanges/bitfinex.py
+++ b/rotkehlchen/exchanges/bitfinex.py
@@ -728,7 +728,7 @@ def _process_unsuccessful_response(  # pylint: disable=no-self-use
             self,
             response: Response,
             case: Literal['balances'],
-    ) -> Tuple[Optional[Dict[Asset, Balance]], str]:
+    ) -> Tuple[Optional[Dict[Asset, Dict[str, FVal]]], str]:
         ...
 
     @overload  # noqa: F811
@@ -754,7 +754,7 @@ def _process_unsuccessful_response(
     ) -> Union[
         List,
         Tuple[bool, str],
-        Tuple[Optional[Dict[Asset, Balance]], str],
+        Tuple[Optional[Dict[Asset, Dict[str, FVal]]], str],
     ]:
         """This function processes not successful responses for the cases listed
         in `case`.
@@ -806,7 +806,7 @@ def first_connection(self) -> None:
 
     @protect_with_lock()
     @cache_response_timewise()
-    def query_balances(self) -> Tuple[Optional[Dict[Asset, Balance]], str]:
+    def query_balances(self) -> Tuple[Optional[Dict[Asset, Dict[str, FVal]]], str]:
         """Return the account exchange balances on Bitfinex
 
         The wallets endpoint returns a list where each item is a currency wallet.
@@ -890,7 +890,7 @@ def query_balances(self) -> Tuple[Optional[Dict[Asset, Balance]], str]:
                 usd_value=amount * usd_price,
             )
 
-        return dict(asset_balance), ''
+        return {a: b.to_dict() for a, b in asset_balance.items()}, ''
 
     def query_online_deposits_withdrawals(
             self,


Test patch:
diff --git a/rotkehlchen/tests/exchanges/test_bitfinex.py b/rotkehlchen/tests/exchanges/test_bitfinex.py
--- a/rotkehlchen/tests/exchanges/test_bitfinex.py
+++ b/rotkehlchen/tests/exchanges/test_bitfinex.py
@@ -198,27 +198,27 @@ def mock_api_query_response(endpoint):  # pylint: disable=unused-argument
             Asset('EUR'): Balance(
                 amount=FVal('99.9999999'),
                 usd_value=FVal('149.99999985'),
-            ),
+            ).to_dict(),
             Asset('GLM'): Balance(
                 amount=FVal('0.0000001'),
                 usd_value=FVal('0.00000015'),
-            ),
+            ).to_dict(),
             Asset('LINK'): Balance(
                 amount=FVal('777.777777'),
                 usd_value=FVal('1166.6666655'),
-            ),
+            ).to_dict(),
             Asset('NEO'): Balance(
                 amount=FVal('1'),
                 usd_value=FVal('1.5'),
-            ),
+            ).to_dict(),
             Asset('USDT'): Balance(
                 amount=FVal('19790.1529257'),
                 usd_value=FVal('29685.22938855'),
-            ),
+            ).to_dict(),
             Asset('WBTC'): Balance(
                 amount=FVal('1'),
                 usd_value=FVal('1.5'),
-            ),
+            ).to_dict(),
         }
         assert msg == ''