Check if order is a dict before parsing

closes #4331
This commit is contained in:
Matthias 2021-02-08 19:35:22 +01:00
parent de727645ab
commit c5ab3a80a5
2 changed files with 13 additions and 1 deletions

View File

@ -171,6 +171,10 @@ class Order(_DECL_BASE):
"""
Get all non-closed orders - useful when trying to batch-update orders
"""
if not isinstance(order, dict):
logger.warning(f"{order} is not a valid response object.")
return
filtered_orders = [o for o in orders if o.order_id == order.get('id')]
if filtered_orders:
oobj = filtered_orders[0]

View File

@ -1074,7 +1074,7 @@ def test_get_best_pair(fee):
@pytest.mark.usefixtures("init_persistence")
def test_update_order_from_ccxt():
def test_update_order_from_ccxt(caplog):
# Most basic order return (only has orderid)
o = Order.parse_from_ccxt_object({'id': '1234'}, 'ETH/BTC', 'buy')
assert isinstance(o, Order)
@ -1120,6 +1120,14 @@ def test_update_order_from_ccxt():
with pytest.raises(DependencyException, match=r"Order-id's don't match"):
o.update_from_ccxt_object(ccxt_order)
message = "aaaa is not a valid response object."
assert not log_has(message, caplog)
Order.update_orders([o], 'aaaa')
assert log_has(message, caplog)
# Call regular update - shouldn't fail.
Order.update_orders([o], {'id': '1234'})
@pytest.mark.usefixtures("init_persistence")
def test_select_order(fee):