Accept filters from request arguments and not only metadata
In DSG metadata is what used to replace the query parameters systems. It is very flexible as it's not in the proto file.
The main inconvenients are:
- The metadata are not binary serialized so passing a lot of data as filters may result in poor performance
- They not exported in the proto so not documented by default.
To contourn that we want to look about best practices and implement it.
Think to update doc after.
@AMontagu, I fully support this reature request.
Right now, I am using a "decorator" workaround, e.g.:
# filter_decorator.py
import functools
import json
import lara_django_samples_grpc.v1.lara_django_samples_pb2 as lara_django_samp_pb2
def dict_filter(func):
@functools.wraps(func)
def wrapper_filter(filter_dict : dict={}, **kwargs):
metadata = (("filters", (json.dumps(filter_dict))),)
return func.List(lara_django_samp_pb2.SampleListRequest(), metadata=metadata, **kwargs)
return wrapper_filter
and then I can do something like:
from filter_decorator import dict_filter
channel = grpc.insecure_channel(f'{grpc_server_host}:{grpc_server_port}')
sample_client = lara_django_samp_pb2_grpc.SampleControllerStub(channel)
list_filter = dict_filter(sample_client)
filter_dict = { "name__contains": "term-to-search"}
res = list_filter(filter_dict=filter_dict)
print(res)
Which is more readable, but still has the problem of using metadata to send the filter.
The first part of this issue is completed. The second part is to precisely detailled the filters and pagination fields names and types instead of using a struct. This improvement may happen in late 2024.