Add warning when CAS paths are skipped and ensure we are under a transaction
This commit is contained in:
parent
69e550d125
commit
62312e6461
2 changed files with 38 additions and 21 deletions
|
@ -7,6 +7,7 @@ import sys
|
|||
import time
|
||||
import uuid
|
||||
|
||||
from contextlib import contextmanager
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from random import SystemRandom
|
||||
|
@ -230,6 +231,7 @@ db_match_func = CallableProxy()
|
|||
db_for_update = CallableProxy()
|
||||
db_transaction = CallableProxy()
|
||||
db_concat_func = CallableProxy()
|
||||
ensure_under_transaction = CallableProxy()
|
||||
|
||||
|
||||
def validate_database_url(url, db_kwargs, connect_timeout=5):
|
||||
|
@ -286,7 +288,16 @@ def configure(config_object):
|
|||
def _db_transaction():
|
||||
return config_object['DB_TRANSACTION_FACTORY'](db)
|
||||
|
||||
@contextmanager
|
||||
def _ensure_under_transaction():
|
||||
if not config_object['TESTING']:
|
||||
if db.transaction_depth() == 0:
|
||||
raise Exception('Expected to be under a transaction')
|
||||
|
||||
yield
|
||||
|
||||
db_transaction.initialize(_db_transaction)
|
||||
ensure_under_transaction.initialize(_ensure_under_transaction)
|
||||
|
||||
def random_string_generator(length=16):
|
||||
def random_string():
|
||||
|
|
Reference in a new issue