Skip to content

Commit

Permalink
Merge 57d7127 into d29023c
Browse files Browse the repository at this point in the history
  • Loading branch information
matt61 committed Oct 4, 2018
2 parents d29023c + 57d7127 commit 62489ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion flask_sqlalchemy_cache/core.py
Expand Up @@ -79,7 +79,7 @@ def get_value(self, merge=True, createfunc=None,
ignore_expiration=ignore_expiration)
else:
cached_value = cache.get(cache_key)
if not cached_value:
if cached_value is None:
cached_value = createfunc()
cache.set(cache_key, cached_value, timeout=expiration_time)

Expand Down
15 changes: 12 additions & 3 deletions flask_sqlalchemy_cache/tests/test_minimal.py
@@ -1,10 +1,12 @@
# coding: UTF-8
import unittest
from unittest.mock import Mock, MagicMock

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy, Model
from flask.ext.cache import Cache
from flask.ext.sqlalchemy_cache import CachingQuery, FromCache
from flask_cache import Cache
from flask_sqlalchemy import SQLAlchemy, Model
from flask_sqlalchemy_cache import CachingQuery, FromCache


Model.query_class = CachingQuery

Expand Down Expand Up @@ -69,6 +71,13 @@ def test_no_results(self):
# regression test (check #3) to handle zero results gracefully
Country.query.filter_by(name="URSS").options(FromCache(cache)).all()

def test_empty_results(self):
# An empty result set should not trigger another set
mock_cache = Mock()
mock_cache.get = MagicMock(return_value=[])
Country.query.filter_by(name="URSS").options(FromCache(mock_cache)).all()
mock_cache.set.assert_not_called()

def test_special_chars(self):
unicode_name = u"Côte d'Ivoire"
unicode_country = Country(unicode_name)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -4,7 +4,7 @@

setup(
name='Flask-SQLAlchemy-Cache',
version='0.1.5',
version='0.1.6',
description='CachingQuery implementation to Flask using Flask-SQLAlchemy and Flask-Cache',
author='Iuri de Silvio',
author_email='iurisilvio@gmail.com',
Expand All @@ -13,7 +13,7 @@
platforms='any',
packages=['flask_sqlalchemy_cache'],
install_requires=[
'Flask>=0.9',
'Flask >=0.12, <1',
'Flask-Cache',
'Flask-SQLAlchemy',
],
Expand Down

0 comments on commit 62489ba

Please sign in to comment.