From c1e4d58ccce8388639700c0d56b2dcba8bf48502 Mon Sep 17 00:00:00 2001 From: cevans87 Date: Tue, 31 Dec 2019 23:23:25 -0800 Subject: [PATCH] Set autocommit for memoize to db --- atools/_memoize_decorator.py | 5 +---- setup.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/atools/_memoize_decorator.py b/atools/_memoize_decorator.py index 3b0c7ab..31d36f3 100644 --- a/atools/_memoize_decorator.py +++ b/atools/_memoize_decorator.py @@ -63,6 +63,7 @@ class _MemoizeBase: def __post_init__(self) -> None: if self.db is not None: + self.db.isolation_level = None return_annotation = inspect.signature(self.fn).return_annotation if not hasattr(return_annotation, '__name__'): object.__setattr__(self, 'db_eval_types', dict(self.fn.__globals__)) @@ -106,7 +107,6 @@ def __post_init__(self) -> None: f"SELECT k, t0 FROM `{self.table_name}` ORDER BY t0" ).fetchall(): self.expire_order[k] = ... - self.db.commit() def __len__(self) -> int: return len(self.memos) @@ -162,7 +162,6 @@ def expire_one_memo(self) -> None: (k, _) = self.memos.popitem(last=False) if (self.db is not None) and (k is not None): self.db.execute(f"DELETE FROM `{self.table_name}` WHERE k = '{k}'") - self.db.commit() def finalize_memo(self, memo: _Memo, key: Union[int, str]) -> Any: if memo.memo_return_state.raised: @@ -185,7 +184,6 @@ def finalize_memo(self, memo: _Memo, key: Union[int, str]) -> Any: value ) ) - self.db.commit() return memo.memo_return_state.value def get_hashed_key(self, key: Tuple[Hashable]) -> Union[int, str]: @@ -205,7 +203,6 @@ def reset(self) -> None: object.__setattr__(self, 'memos', OrderedDict()) if self.db is not None: self.db.execute(f"DELETE FROM `{self.table_name}`") - self.db.commit() def reset_key(self, key: Union[int, str]) -> None: if key in self.memos: diff --git a/setup.py b/setup.py index 723457b..ee2987c 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='atools', - version='0.10.3', + version='0.10.4', packages=find_packages(), python_requires='>=3.6', url='https://github.com/cevans87/atools',