aiohttp_json_api
aiohttp_json_api copied to clipboard
Improper sorting order for some cases
- aiohttp JSON API version: 0.37.0
- Python version: 3.7.0
- Operating System: ArchLinux (w/ 4.18.8 kernel)
Description
In some rare cases JSONAPIContext doesn't follow JSONAPI specs about sorting order.
It happens when a field with - prefix is followed by a field without prefix (see example below).
What I Did
In [1]: from aiohttp_json_api.context import JSONAPIContext
In [2]: class Request:
...: # Imitate aiohttp request
...: query = {'sort': '-field1,field2,+field3'}
...:
In [3]: JSONAPIContext.parse_request_sorting(Request())
Out[3]:
OrderedDict([(('field1',), <SortDirection.DESC: '-'>),
(('field2',), <SortDirection.DESC: '-'>),
(('field3',), <SortDirection.ASC: '+'>)])
In according with the specs, field2 must have an ascending order.
It seems that this misbehaviour is caused by these lines and direction variable should be initialize inside the loop.