<commit_before>"""
Middleware!
"""
from django_tenant_templates import local


class TenantMiddleware(object):
    """Middleware for enabling tenant-aware template loading."""
    slug_property_name = 'tenant_slug'

    def process_request(self, request):
        local.tenant_slug = getattr(request, self.slug_property_name, None)<commit_msg>Remove the thread local on exceptions<commit_after>"""
Middleware!
"""
from django_tenant_templates import local


class TenantMiddleware(object):
    """Middleware for enabling tenant-aware template loading."""
    slug_property_name = 'tenant_slug'

    def process_request(self, request):
        local.tenant_slug = getattr(request, self.slug_property_name, None)

    def process_exception(self, request, exception):
        try:
            del local.tenant_slug
        except AttributeError:
            pass
{'fraction_non_alphanumeric': 0.09080325960419092, 'fraction_numerical': 0.0, 'mean_word_length': 4.180722891566265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7375132', 'n_tokens_mistral': 229, 'n_tokens_neox': 242, 'n_words': 60}