Skip to content

Commit

Permalink
Invalidates executemany.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Dec 7, 2014
1 parent 3293c2c commit 984b3f2
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cachalot/monkey_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,21 @@ def _patch_orm():
def _patch_cursor():
def _patch_cursor_execute(original):
@wraps(original)
def inner(cursor, sql, params=None):
out = original(cursor, sql, params)
def inner(cursor, sql, *args, **kwargs):
out = original(cursor, sql, *args, **kwargs)
if getattr(cursor.db, 'raw', True) \
and cachalot_settings.CACHALOT_INVALIDATE_RAW:
full_sql = sql
if params:
full_sql %= tuple(params)
full_sql = full_sql.lower()
if 'update' in full_sql or 'insert' in full_sql \
or 'delete' in full_sql:
tables = _get_tables_from_sql(cursor.db, full_sql)
sql = sql.lower()
if 'update' in sql or 'insert' in sql or 'delete' in sql:
tables = _get_tables_from_sql(cursor.db, sql)
invalidate_tables(tables, db_alias=cursor.db.alias)
return out

inner.original = original
return inner

CursorWrapper.execute = _patch_cursor_execute(CursorWrapper.execute)
CursorWrapper.executemany = _patch_cursor_execute(CursorWrapper.executemany)


def _patch_atomic():
Expand Down

0 comments on commit 984b3f2

Please sign in to comment.