We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Filter warehouses by metadata
There are stores that have hundreds of warehouses, for performing updates metadata can be useful as a lookup mechanism instead of using externalReference

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `saleor/graphql/warehouse/filters.py`
Content:
```
1 import django_filters
2 import graphene
3 from django.db.models import Exists, OuterRef, Q
4 
5 from ...account.models import Address
6 from ...product.models import Product, ProductVariant
7 from ...warehouse import WarehouseClickAndCollectOption
8 from ...warehouse.models import Stock, Warehouse
9 from ..channel.types import Channel
10 from ..core.doc_category import DOC_CATEGORY_PRODUCTS
11 from ..core.filters import (
12     EnumFilter,
13     GlobalIDMultipleChoiceFilter,
14     ListObjectTypeFilter,
15     filter_slug_list,
16 )
17 from ..core.types import FilterInputObjectType
18 from ..utils import resolve_global_ids_to_primary_keys
19 from ..warehouse.enums import WarehouseClickAndCollectOptionEnum
20 
21 
22 def prefech_qs_for_filter(qs):
23     return qs.prefetch_related("address")
24 
25 
26 def filter_search_warehouse(qs, _, value):
27     if value:
28         addresses = Address.objects.filter(
29             Q(company_name__ilike=value)
30             | Q(street_address_1__ilike=value)
31             | Q(street_address_2__ilike=value)
32             | Q(city__ilike=value)
33             | Q(postal_code__ilike=value)
34             | Q(phone__ilike=value)
35         ).values("pk")
36         qs = qs.filter(
37             Q(name__ilike=value)
38             | Q(email__ilike=value)
39             | Q(Exists(addresses.filter(pk=OuterRef("address_id"))))
40         )
41     return qs
42 
43 
44 def filter_click_and_collect_option(qs, _, value):
45     if value == WarehouseClickAndCollectOptionEnum.LOCAL.value:
46         qs = qs.filter(
47             click_and_collect_option=WarehouseClickAndCollectOption.LOCAL_STOCK
48         )
49     elif value == WarehouseClickAndCollectOptionEnum.ALL.value:
50         qs = qs.filter(
51             click_and_collect_option=WarehouseClickAndCollectOption.ALL_WAREHOUSES
52         )
53     elif value == WarehouseClickAndCollectOptionEnum.DISABLED.value:
54         qs = qs.filter(click_and_collect_option=WarehouseClickAndCollectOption.DISABLED)
55     return qs
56 
57 
58 def filter_channels(qs, _, values):
59     if values:
60         _, channels_ids = resolve_global_ids_to_primary_keys(values, Channel)
61         WarehouseChannel = Warehouse.channels.through
62         warehouse_channels = WarehouseChannel.objects.filter(
63             channel_id__in=channels_ids
64         )
65         qs = qs.filter(Exists(warehouse_channels.filter(warehouse_id=OuterRef("id"))))
66     return qs
67 
68 
69 def filter_search_stock(qs, _, value):
70     if value:
71         products = Product.objects.filter(name__ilike=value).values("pk")
72         variants = ProductVariant.objects.filter(
73             Q(name__ilike=value) | Q(Exists(products.filter(pk=OuterRef("product_id"))))
74         ).values("pk")
75         addresses = Address.objects.filter(company_name__ilike=value)
76         warehouses = Warehouse.objects.filter(
77             Q(name__ilike=value)
78             | Q(Exists(addresses.filter(id=OuterRef("address_id"))))
79         ).values("pk")
80         return qs.filter(
81             Q(Exists(variants.filter(pk=OuterRef("product_variant_id"))))
82             | Q(Exists(warehouses.filter(stock=OuterRef("pk"))))
83         )
84     return qs
85 
86 
87 class WarehouseFilter(django_filters.FilterSet):
88     search = django_filters.CharFilter(method=filter_search_warehouse)
89     ids = GlobalIDMultipleChoiceFilter(field_name="id")
90     is_private = django_filters.BooleanFilter(field_name="is_private")
91     click_and_collect_option = EnumFilter(
92         input_class=WarehouseClickAndCollectOptionEnum,
93         method=filter_click_and_collect_option,
94     )
95     channels = GlobalIDMultipleChoiceFilter(method=filter_channels)
96     slugs = ListObjectTypeFilter(input_class=graphene.String, method=filter_slug_list)
97 
98     class Meta:
99         model = Warehouse
100         fields = ["click_and_collect_option"]
101 
102 
103 class WarehouseFilterInput(FilterInputObjectType):
104     class Meta:
105         doc_category = DOC_CATEGORY_PRODUCTS
106         filterset_class = WarehouseFilter
107 
108 
109 class StockFilter(django_filters.FilterSet):
110     search = django_filters.CharFilter(method=filter_search_stock)
111 
112     class Meta:
113         model = Stock
114         fields = ["quantity"]
115 
116 
117 class StockFilterInput(FilterInputObjectType):
118     class Meta:
119         doc_category = DOC_CATEGORY_PRODUCTS
120         filterset_class = StockFilter
121
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/saleor/graphql/warehouse/filters.py b/saleor/graphql/warehouse/filters.py
--- a/saleor/graphql/warehouse/filters.py
+++ b/saleor/graphql/warehouse/filters.py
@@ -12,6 +12,7 @@
     EnumFilter,
     GlobalIDMultipleChoiceFilter,
     ListObjectTypeFilter,
+    MetadataFilterBase,
     filter_slug_list,
 )
 from ..core.types import FilterInputObjectType
@@ -84,7 +85,7 @@
     return qs
 
 
-class WarehouseFilter(django_filters.FilterSet):
+class WarehouseFilter(MetadataFilterBase):
     search = django_filters.CharFilter(method=filter_search_warehouse)
     ids = GlobalIDMultipleChoiceFilter(field_name="id")
     is_private = django_filters.BooleanFilter(field_name="is_private")

{"golden_diff": "diff --git a/saleor/graphql/warehouse/filters.py b/saleor/graphql/warehouse/filters.py\n--- a/saleor/graphql/warehouse/filters.py\n+++ b/saleor/graphql/warehouse/filters.py\n@@ -12,6 +12,7 @@\n     EnumFilter,\n     GlobalIDMultipleChoiceFilter,\n     ListObjectTypeFilter,\n+    MetadataFilterBase,\n     filter_slug_list,\n )\n from ..core.types import FilterInputObjectType\n@@ -84,7 +85,7 @@\n     return qs\n \n \n-class WarehouseFilter(django_filters.FilterSet):\n+class WarehouseFilter(MetadataFilterBase):\n     search = django_filters.CharFilter(method=filter_search_warehouse)\n     ids = GlobalIDMultipleChoiceFilter(field_name=\"id\")\n     is_private = django_filters.BooleanFilter(field_name=\"is_private\")\n", "issue": "Filter warehouses by metadata\nThere are stores that have hundreds of warehouses, for performing updates metadata can be useful as a lookup mechanism instead of using externalReference\n", "before_files": [{"content": "import django_filters\nimport graphene\nfrom django.db.models import Exists, OuterRef, Q\n\nfrom ...account.models import Address\nfrom ...product.models import Product, ProductVariant\nfrom ...warehouse import WarehouseClickAndCollectOption\nfrom ...warehouse.models import Stock, Warehouse\nfrom ..channel.types import Channel\nfrom ..core.doc_category import DOC_CATEGORY_PRODUCTS\nfrom ..core.filters import (\n    EnumFilter,\n    GlobalIDMultipleChoiceFilter,\n    ListObjectTypeFilter,\n    filter_slug_list,\n)\nfrom ..core.types import FilterInputObjectType\nfrom ..utils import resolve_global_ids_to_primary_keys\nfrom ..warehouse.enums import WarehouseClickAndCollectOptionEnum\n\n\ndef prefech_qs_for_filter(qs):\n    return qs.prefetch_related(\"address\")\n\n\ndef filter_search_warehouse(qs, _, value):\n    if value:\n        addresses = Address.objects.filter(\n            Q(company_name__ilike=value)\n            | Q(street_address_1__ilike=value)\n            | Q(street_address_2__ilike=value)\n            | Q(city__ilike=value)\n            | Q(postal_code__ilike=value)\n            | Q(phone__ilike=value)\n        ).values(\"pk\")\n        qs = qs.filter(\n            Q(name__ilike=value)\n            | Q(email__ilike=value)\n            | Q(Exists(addresses.filter(pk=OuterRef(\"address_id\"))))\n        )\n    return qs\n\n\ndef filter_click_and_collect_option(qs, _, value):\n    if value == WarehouseClickAndCollectOptionEnum.LOCAL.value:\n        qs = qs.filter(\n            click_and_collect_option=WarehouseClickAndCollectOption.LOCAL_STOCK\n        )\n    elif value == WarehouseClickAndCollectOptionEnum.ALL.value:\n        qs = qs.filter(\n            click_and_collect_option=WarehouseClickAndCollectOption.ALL_WAREHOUSES\n        )\n    elif value == WarehouseClickAndCollectOptionEnum.DISABLED.value:\n        qs = qs.filter(click_and_collect_option=WarehouseClickAndCollectOption.DISABLED)\n    return qs\n\n\ndef filter_channels(qs, _, values):\n    if values:\n        _, channels_ids = resolve_global_ids_to_primary_keys(values, Channel)\n        WarehouseChannel = Warehouse.channels.through\n        warehouse_channels = WarehouseChannel.objects.filter(\n            channel_id__in=channels_ids\n        )\n        qs = qs.filter(Exists(warehouse_channels.filter(warehouse_id=OuterRef(\"id\"))))\n    return qs\n\n\ndef filter_search_stock(qs, _, value):\n    if value:\n        products = Product.objects.filter(name__ilike=value).values(\"pk\")\n        variants = ProductVariant.objects.filter(\n            Q(name__ilike=value) | Q(Exists(products.filter(pk=OuterRef(\"product_id\"))))\n        ).values(\"pk\")\n        addresses = Address.objects.filter(company_name__ilike=value)\n        warehouses = Warehouse.objects.filter(\n            Q(name__ilike=value)\n            | Q(Exists(addresses.filter(id=OuterRef(\"address_id\"))))\n        ).values(\"pk\")\n        return qs.filter(\n            Q(Exists(variants.filter(pk=OuterRef(\"product_variant_id\"))))\n            | Q(Exists(warehouses.filter(stock=OuterRef(\"pk\"))))\n        )\n    return qs\n\n\nclass WarehouseFilter(django_filters.FilterSet):\n    search = django_filters.CharFilter(method=filter_search_warehouse)\n    ids = GlobalIDMultipleChoiceFilter(field_name=\"id\")\n    is_private = django_filters.BooleanFilter(field_name=\"is_private\")\n    click_and_collect_option = EnumFilter(\n        input_class=WarehouseClickAndCollectOptionEnum,\n        method=filter_click_and_collect_option,\n    )\n    channels = GlobalIDMultipleChoiceFilter(method=filter_channels)\n    slugs = ListObjectTypeFilter(input_class=graphene.String, method=filter_slug_list)\n\n    class Meta:\n        model = Warehouse\n        fields = [\"click_and_collect_option\"]\n\n\nclass WarehouseFilterInput(FilterInputObjectType):\n    class Meta:\n        doc_category = DOC_CATEGORY_PRODUCTS\n        filterset_class = WarehouseFilter\n\n\nclass StockFilter(django_filters.FilterSet):\n    search = django_filters.CharFilter(method=filter_search_stock)\n\n    class Meta:\n        model = Stock\n        fields = [\"quantity\"]\n\n\nclass StockFilterInput(FilterInputObjectType):\n    class Meta:\n        doc_category = DOC_CATEGORY_PRODUCTS\n        filterset_class = StockFilter\n", "path": "saleor/graphql/warehouse/filters.py"}], "after_files": [{"content": "import django_filters\nimport graphene\nfrom django.db.models import Exists, OuterRef, Q\n\nfrom ...account.models import Address\nfrom ...product.models import Product, ProductVariant\nfrom ...warehouse import WarehouseClickAndCollectOption\nfrom ...warehouse.models import Stock, Warehouse\nfrom ..channel.types import Channel\nfrom ..core.doc_category import DOC_CATEGORY_PRODUCTS\nfrom ..core.filters import (\n    EnumFilter,\n    GlobalIDMultipleChoiceFilter,\n    ListObjectTypeFilter,\n    MetadataFilterBase,\n    filter_slug_list,\n)\nfrom ..core.types import FilterInputObjectType\nfrom ..utils import resolve_global_ids_to_primary_keys\nfrom ..warehouse.enums import WarehouseClickAndCollectOptionEnum\n\n\ndef prefech_qs_for_filter(qs):\n    return qs.prefetch_related(\"address\")\n\n\ndef filter_search_warehouse(qs, _, value):\n    if value:\n        addresses = Address.objects.filter(\n            Q(company_name__ilike=value)\n            | Q(street_address_1__ilike=value)\n            | Q(street_address_2__ilike=value)\n            | Q(city__ilike=value)\n            | Q(postal_code__ilike=value)\n            | Q(phone__ilike=value)\n        ).values(\"pk\")\n        qs = qs.filter(\n            Q(name__ilike=value)\n            | Q(email__ilike=value)\n            | Q(Exists(addresses.filter(pk=OuterRef(\"address_id\"))))\n        )\n    return qs\n\n\ndef filter_click_and_collect_option(qs, _, value):\n    if value == WarehouseClickAndCollectOptionEnum.LOCAL.value:\n        qs = qs.filter(\n            click_and_collect_option=WarehouseClickAndCollectOption.LOCAL_STOCK\n        )\n    elif value == WarehouseClickAndCollectOptionEnum.ALL.value:\n        qs = qs.filter(\n            click_and_collect_option=WarehouseClickAndCollectOption.ALL_WAREHOUSES\n        )\n    elif value == WarehouseClickAndCollectOptionEnum.DISABLED.value:\n        qs = qs.filter(click_and_collect_option=WarehouseClickAndCollectOption.DISABLED)\n    return qs\n\n\ndef filter_channels(qs, _, values):\n    if values:\n        _, channels_ids = resolve_global_ids_to_primary_keys(values, Channel)\n        WarehouseChannel = Warehouse.channels.through\n        warehouse_channels = WarehouseChannel.objects.filter(\n            channel_id__in=channels_ids\n        )\n        qs = qs.filter(Exists(warehouse_channels.filter(warehouse_id=OuterRef(\"id\"))))\n    return qs\n\n\ndef filter_search_stock(qs, _, value):\n    if value:\n        products = Product.objects.filter(name__ilike=value).values(\"pk\")\n        variants = ProductVariant.objects.filter(\n            Q(name__ilike=value) | Q(Exists(products.filter(pk=OuterRef(\"product_id\"))))\n        ).values(\"pk\")\n        addresses = Address.objects.filter(company_name__ilike=value)\n        warehouses = Warehouse.objects.filter(\n            Q(name__ilike=value)\n            | Q(Exists(addresses.filter(id=OuterRef(\"address_id\"))))\n        ).values(\"pk\")\n        return qs.filter(\n            Q(Exists(variants.filter(pk=OuterRef(\"product_variant_id\"))))\n            | Q(Exists(warehouses.filter(stock=OuterRef(\"pk\"))))\n        )\n    return qs\n\n\nclass WarehouseFilter(MetadataFilterBase):\n    search = django_filters.CharFilter(method=filter_search_warehouse)\n    ids = GlobalIDMultipleChoiceFilter(field_name=\"id\")\n    is_private = django_filters.BooleanFilter(field_name=\"is_private\")\n    click_and_collect_option = EnumFilter(\n        input_class=WarehouseClickAndCollectOptionEnum,\n        method=filter_click_and_collect_option,\n    )\n    channels = GlobalIDMultipleChoiceFilter(method=filter_channels)\n    slugs = ListObjectTypeFilter(input_class=graphene.String, method=filter_slug_list)\n\n    class Meta:\n        model = Warehouse\n        fields = [\"click_and_collect_option\"]\n\n\nclass WarehouseFilterInput(FilterInputObjectType):\n    class Meta:\n        doc_category = DOC_CATEGORY_PRODUCTS\n        filterset_class = WarehouseFilter\n\n\nclass StockFilter(django_filters.FilterSet):\n    search = django_filters.CharFilter(method=filter_search_stock)\n\n    class Meta:\n        model = Stock\n        fields = [\"quantity\"]\n\n\nclass StockFilterInput(FilterInputObjectType):\n    class Meta:\n        doc_category = DOC_CATEGORY_PRODUCTS\n        filterset_class = StockFilter\n", "path": "saleor/graphql/warehouse/filters.py"}]}