Commit ad8180b9 authored by Jens Langhammer's avatar Jens Langhammer

Fix nasty caching bug causing Rules to work depending on order they were first evaluated in.

parent 8864d177
Pipeline #3835 passed with stage
in 1 minute and 46 seconds
......@@ -56,6 +56,7 @@ class ServeRoutingMiddleware:
def get_blob_from_rule(self):
"""Try to lookup blob from ServeRule, raise Http404 if none found"""
for rule in ServeRule.objects.all():
LOGGER.debug("Trying rule %s", rule.name)
if rule.matches(self.request):
LOGGER.debug("Rule %s matched", rule)
lookups, messages = self.rule_lookup(rule)
......
......@@ -21,14 +21,6 @@ class ServeRule(TagModel, UUIDModel):
name = models.TextField()
blob_query = models.TextField()
_compiled_regex = {}
def _regex(self, key):
"""Compiled regex and cache instance"""
if key not in self._compiled_regex:
self._compiled_regex[key] = re.compile(self.tags.get(key, ""))
return self._compiled_regex[key]
def matches(self, request):
"""Return true if request matches our tags, false if not"""
for tag_key, tag_value in self.tags.items():
......@@ -42,10 +34,13 @@ class ServeRule(TagModel, UUIDModel):
elif tag_key.startswith(TAG_SERVE_MATCH_META):
meta_key = tag_key.replace(TAG_SERVE_MATCH_META, '')
request_value = request.META.get(meta_key, '')
LOGGER.debug("Checking %s against %s", request_value, tag_value)
if not self._regex(tag_key).match(request_value):
LOGGER.debug("Checking '%s' against '%s'", request_value, tag_value)
regex = re.compile(tag_value)
match = regex.match(request_value)
if match is None:
LOGGER.debug(" => Not matching")
return False
LOGGER.debug(" => Matching, checking next tag")
return True
def __str__(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment