1. Krzysztof Bandurski
  2. johnny-cache

Commits

Krzysztof Bandurski  committed 49f2b7a

Fixed a sentinel-related bug.

  • Participants
  • Parent commits 318cbcc
  • Branches default

Comments (0)

Files changed (1)

File johnny/cache.py

View file
                 signals.qc_hit.send(sender=cls, tables=tables,
                         query=(sql, params, cls.query.ordering_aliases),
                         size=len(val), key=key)
-                if val is sentinel:
+                
+                # We cannot do: if val is sentinel: ...
+                # Because the encoding in the settings file may be different
+                # than the encoding in this file.
+                if val == sentinel:
                     return None
                 return val
 
                 #todo - create a smart iterable wrapper
                 val = list(val)
             if key is not None:
-                self.cache_backend.set(key, val or sentinel, settings.MIDDLEWARE_SECONDS, db)
+                cached_val = val
+                # We cannot just do: cached_val = val or sentinel
+                # Because val can be something like [] (an empty queryset)
+                if cached_val is None:
+                    cached_val = sentinel
+                self.cache_backend.set(key, cached_val, settings.MIDDLEWARE_SECONDS, db)
             return val
         return newfun