Rollback after each request
This closes the transaction and avoids "sticking" transactions.
This commit is contained in:
parent
89ca8abea9
commit
fb2c8f7621
@ -1,4 +1,4 @@
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Dict, Iterator, Optional
|
||||
|
||||
from freqtrade.persistence import Trade
|
||||
from freqtrade.rpc.rpc import RPC, RPCException
|
||||
@ -12,11 +12,12 @@ def get_rpc_optional() -> Optional[RPC]:
|
||||
return None
|
||||
|
||||
|
||||
def get_rpc() -> Optional[RPC]:
|
||||
def get_rpc() -> Optional[Iterator[RPC]]:
|
||||
_rpc = get_rpc_optional()
|
||||
if _rpc:
|
||||
Trade.query.session.rollback()
|
||||
return _rpc
|
||||
yield _rpc
|
||||
Trade.query.session.rollback()
|
||||
else:
|
||||
raise RPCException('Bot is not in the correct state')
|
||||
|
||||
|
@ -227,7 +227,6 @@ def create_mock_trades(fee, use_db: bool = True):
|
||||
|
||||
if use_db:
|
||||
Trade.commit()
|
||||
Trade.query.session.flush()
|
||||
|
||||
|
||||
def create_mock_trades_usdt(fee, use_db: bool = True):
|
||||
@ -261,7 +260,6 @@ def create_mock_trades_usdt(fee, use_db: bool = True):
|
||||
|
||||
if use_db:
|
||||
Trade.commit()
|
||||
Trade.query.session.flush()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -570,7 +570,6 @@ def test_api_trades(botclient, mocker, fee, markets):
|
||||
assert rc.json()['total_trades'] == 0
|
||||
|
||||
create_mock_trades(fee)
|
||||
Trade.query.session.flush()
|
||||
|
||||
rc = client_get(client, f"{BASE_URI}/trades")
|
||||
assert_response(rc)
|
||||
@ -597,7 +596,6 @@ def test_api_trade_single(botclient, mocker, fee, ticker, markets):
|
||||
assert rc.json()['detail'] == 'Trade not found.'
|
||||
|
||||
create_mock_trades(fee)
|
||||
Trade.query.session.flush()
|
||||
|
||||
rc = client_get(client, f"{BASE_URI}/trade/3")
|
||||
assert_response(rc)
|
||||
@ -694,7 +692,6 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets):
|
||||
assert rc.json() == {"error": "Error querying /api/v1/edge: Edge is not enabled."}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_api_profit(botclient, mocker, ticker, fee, markets):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot)
|
||||
@ -745,7 +742,6 @@ def test_api_profit(botclient, mocker, ticker, fee, markets):
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_api_stats(botclient, mocker, ticker, fee, markets,):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot)
|
||||
@ -811,7 +807,7 @@ def test_api_performance(botclient, fee):
|
||||
trade.close_profit_abs = trade.calc_profit()
|
||||
|
||||
Trade.query.session.add(trade)
|
||||
Trade.query.session.flush()
|
||||
Trade.commit()
|
||||
|
||||
rc = client_get(client, f"{BASE_URI}/performance")
|
||||
assert_response(rc)
|
||||
|
Loading…
Reference in New Issue
Block a user