Skip to content

QueryArrayWidget does not work with the foo=bar,baz syntax #1685

@gabn88

Description

@gabn88

According to the docs (

class QueryArrayWidget(BaseCSVWidget, forms.TextInput):
) the QueryArrayWidget should work with the foo=bar,baz syntax. It does however test for this syntax by testing for MultiValueDict.

The problem here is that a QueryDict (the actual data type) is a subclass of MultiValueDict and the result always returns False and the data never get into the if statement.

I fixed it by replacing the code with:

        if not type(data) == MultiValueDict:
            data = data.copy()
            ret = {}
            for key, value in data.items():
                if type(value) == list:
                    value = list[0]
                # treat value as csv string: ?foo=1,2
                if isinstance(value, str):
                    ret[key] = [x.strip() for x in value.rstrip(",").split(",") if x]
            data = MultiValueDict(ret)

But I'm sure there must be a better fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions