Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for a list of expansions with multiple expand parameters instead of separated by a comma. #137

Open
SorianoMarmol opened this issue Nov 15, 2023 · 1 comment

Comments

@SorianoMarmol
Copy link

SorianoMarmol commented Nov 15, 2023

Hello. First of all, thank you for your work and effort with the library!

We have noticed that, despite expansions working correctly with multiple expansion parameters:

expand=field1&expand=field2 instead of ?expand=field1,field2

the 'is_expanded' function does not respond appropriately due to the use of 'request.query_params.get(EXPAND_PARAM).'
In the case of receiving a list, it only returns one of the values.

However, the 'getlist' method does return both fields.
I illustrate it with an example:

# expand=field1&expand=field2
ipdb> self.request.query_params
<QueryDict: {'expand': ['asset', 'positions']}>
ipdb> self.request.query_params.getlist('expand')
['field1', 'field2']
ipdb> self.request.query_params.get('expand')
'field2'

In this case, it's already a list.

Would it be possible to manage this scenario as well?

@SorianoMarmol
Copy link
Author

Something like that

def is_expanded(request, field: str) -> bool:
    """ Examines request object to return boolean of whether
        passed field is expanded.
    """
    expand_value = request.query_params.getlist(EXPAND_PARAM)
    if not expand_value:
        return False
    expand_fields = []
    if len(expand_value) > 1:  # already a list
        expand_params = expand_value
    else:
        expand_params = expand_value[0].split(",")
    for f in expand_params:
        expand_fields.extend([_ for _ in f.split(".")])

    return any(field for field in expand_fields if field in WILDCARD_VALUES) or field in expand_fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant