Skip to content

Commit

Permalink
expunge_all() before commit in atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
epandurski committed Feb 10, 2019
1 parent 9e4701c commit 5c44e77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions flask_signalbus/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def wrapper(*args, **kwargs):
session_info[_ATOMIC_FLAG_SESSION_INFO_KEY] = True
try:
result = f(*args, **kwargs)
session.flush()
session.expunge_all()
session.commit()
return result
except Exception:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def test_retry_on_integrity_error(atomic_db, AtomicModel):
@db.execute_atomic
def t1():
with db.retry_on_integrity_error():
db.session.merge(o)
return db.session.merge(o)
assert len(AtomicModel.query.all()) == 1
assert t1 not in db.session
assert t1.name == 'test'
assert t1.value == '1'

db.session.expunge_all()
o.value = '2'
Expand Down

0 comments on commit 5c44e77

Please sign in to comment.