Commit d59f2f3f authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

util: move the transaction checker decorator

parent d4d4a4571986
......@@ -8,7 +8,6 @@ import pandas as pd
from sqlalchemy import Table, Column, Integer, ForeignKey, Index
from sqlalchemy.sql.elements import NONE_NAME
from sqlalchemy.engine.base import Engine
from sqlalchemy.sql.expression import select, func, desc
from sqlalchemy.dialects.postgresql import TIMESTAMP
......@@ -18,6 +17,7 @@ from tshistory.util import (
num2float,
SeriesServices,
start_end,
tx,
tzaware_serie
)
from tshistory.snapshot import Snapshot, TABLES as SNAPTABLES
......@@ -26,17 +26,6 @@ L = logging.getLogger('tshistory.tsio')
TABLES = {}
def tx(func):
def check_tx_and_call(self, cn, *a, **kw):
# safety belt to make sure important api points are tx-safe
if isinstance(cn, Engine) or not cn.in_transaction():
if not getattr(self, '_testing', False):
raise TypeError('You must use a transaction object')
return func(self, cn, *a, **kw)
return check_tx_and_call
class TimeSerie(SeriesServices):
namespace = 'tsh'
schema = None
......
......@@ -13,6 +13,7 @@ import pandas as pd
from pandas.api.types import is_datetimetz
from sqlalchemy.sql.expression import text
from sqlalchemy.engine import url
from sqlalchemy.engine.base import Engine
from inireader import reader
......@@ -231,6 +232,18 @@ def threadpool(maxthreads):
return run
def tx(func):
" a decorator to check that the first method argument is a transaction "
def check_tx_and_call(self, cn, *a, **kw):
# safety belt to make sure important api points are tx-safe
if isinstance(cn, Engine) or not cn.in_transaction():
if not getattr(self, '_testing', False):
raise TypeError('You must use a transaction object')
return func(self, cn, *a, **kw)
return check_tx_and_call
class unilist(list):
" a list which refuses duplicates "
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment