Skip to content

Commit dd09948

Browse files
committed
fix: Prevent memory leaks when checking if the search method accepts an info keyword
1 parent 53eac6b commit dd09948

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "strawberry-graphql-django"
33
packages = [{ include = "strawberry_django" }]
4-
version = "0.7"
4+
version = "0.7.1"
55
description = "Strawberry GraphQL Django extension"
66
authors = ["Lauri Hintsala <[email protected]>"]
77
repository = "https://github.com/strawberry-graphql/strawberry-graphql-django"

strawberry_django/filters.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def build_filter_kwargs(filters):
123123
return filter_kwargs, filter_methods
124124

125125

126-
@functools.lru_cache(maxsize=None)
126+
@functools.lru_cache(maxsize=256)
127127
def function_allow_passing_info(filter_method: FunctionType) -> bool:
128128
argspec = inspect.getfullargspec(filter_method)
129129

@@ -146,7 +146,10 @@ def apply(filters, queryset: QuerySet, info=UNSET, pk=UNSET) -> QuerySet:
146146

147147
filter_method = getattr(filters, "filter", None)
148148
if filter_method:
149-
if function_allow_passing_info(filter_method):
149+
if function_allow_passing_info(
150+
# Pass the original __func__ which is always the same
151+
getattr(filter_method, "__func__", filter_method)
152+
):
150153
return filter_method(queryset=queryset, info=info)
151154

152155
else:
@@ -155,7 +158,10 @@ def apply(filters, queryset: QuerySet, info=UNSET, pk=UNSET) -> QuerySet:
155158
filter_kwargs, filter_methods = build_filter_kwargs(filters)
156159
queryset = queryset.filter(**filter_kwargs)
157160
for filter_method in filter_methods:
158-
if function_allow_passing_info(filter_method):
161+
if function_allow_passing_info(
162+
# Pass the original __func__ which is always the same
163+
getattr(filter_method, "__func__", filter_method)
164+
):
159165
queryset = filter_method(queryset=queryset, info=info)
160166

161167
else:

0 commit comments

Comments
 (0)