mrf345/flask_minify

Cache KeyError

KTibow opened this issue · 2 comments

In my code, I've been using flask_minify, and I've been disabling the cache (for dynamic reasons). When I saw this PR from Dependabot on my repo, I saw that the checks passed, so I merged it in. Whenever I tried to connect to the server, though, it gave me this exception:

 Traceback (most recent call last):
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
     response = self.full_dispatch_request()
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1953, in full_dispatch_request
     return self.finalize_request(rv)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1970, in finalize_request
     response = self.process_response(response)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2267, in process_response
     response = handler(response)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask_minify/main.py", line 273, in main
     'style'))
   File "/app/.heroku/python/lib/python3.6/site-packages/flask_minify/main.py", line 220, in get_minified_or_cached
     limit_reached and self.cache[self.endpoint].popitem()
 KeyError: 'something'
 Traceback (most recent call last):
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
     response = self.full_dispatch_request()
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1953, in full_dispatch_request
     return self.finalize_request(rv)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1970, in finalize_request
     response = self.process_response(response)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2267, in process_response
     response = handler(response)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask_minify/main.py", line 273, in main
     'style'))
   File "/app/.heroku/python/lib/python3.6/site-packages/flask_minify/main.py", line 220, in get_minified_or_cached
     limit_reached and self.cache[self.endpoint].popitem()
 KeyError: 'something'
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1970, in finalize_request
     response = self.process_response(response)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2267, in process_response
     response = handler(response)
   File "/app/.heroku/python/lib/python3.6/site-packages/flask_minify/main.py", line 266, in main
     self.html))
   File "/app/.heroku/python/lib/python3.6/site-packages/flask_minify/main.py", line 220, in get_minified_or_cached
     limit_reached and self.cache[self.endpoint].popitem()
 KeyError: 'something'

What's going on here? How can I fix it?

I did minor refactoring yesterday, mainly to fix self.static option being ignored #31
But it seems i missed an edge-case that occurs when the self.caching_limit is set to 0 🤦‍♂️

I've added a fail-safe and included the edge-case in the integration test case #33

Should be now resolved pip install Flask-Minify==0.23