From ce6b079771b1ab493afd050005347b6ce3a91f7e Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 11 Nov 2025 09:53:11 +0100 Subject: [PATCH] fix: command cache key with special letters --- src/unfold/sites.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/unfold/sites.py b/src/unfold/sites.py index aa7d8120a..9257131a7 100644 --- a/src/unfold/sites.py +++ b/src/unfold/sites.py @@ -1,4 +1,5 @@ import copy +import hashlib import time from collections.abc import Callable from http import HTTPStatus @@ -12,9 +13,9 @@ from django.http import HttpRequest, HttpResponse from django.template.response import TemplateResponse from django.urls import URLPattern, path, reverse, reverse_lazy +from django.utils.encoding import force_bytes from django.utils.functional import lazy from django.utils.module_loading import import_string -from django.utils.text import slugify from unfold.dataclasses import DropdownItem, Favicon, SearchResult @@ -284,7 +285,10 @@ def search( return HttpResponse() search_term = search_term.lower() - cache_key = f"unfold_search_{request.user.pk}_{slugify(search_term)}" + search_key_base = f"{request.user.pk}_{search_term}" + cache_key = ( + f"unfold_search_{hashlib.sha256(force_bytes(search_key_base)).hexdigest()}" + ) cache_results = cache.get(cache_key) if extended_search: