Skip to content

Commit

Permalink
Skipping Cache Invalidations for Unsupported Raw Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Yogesh Kumar committed Oct 30, 2023
1 parent b411e00 commit 3c0fa5d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cachalot/monkey_patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import warnings
from collections.abc import Iterable
from functools import wraps
from time import time
Expand Down Expand Up @@ -140,6 +141,15 @@ def inner(cursor, sql, *args, **kwargs):
if getattr(connection, 'raw', True):
if isinstance(sql, bytes):
sql = sql.decode('utf-8')
# in case `sql` is not of type `str`,
# we raise a warning and return.
if not isinstance(sql, str):
warnings.warn(
f"Unsupported sql of type {type(sql)}, "
f"skipping raw query cache invalidation's. "
f"Try setting `CACHALOT_INVALIDATE_RAW` to False."
)
return
sql = sql.lower()
if SQL_DATA_CHANGE_RE.search(sql):
tables = filter_cachable(
Expand Down

0 comments on commit 3c0fa5d

Please sign in to comment.