1b6856d5ef
The idea behind this patch is to disable default sorting for inner listing operation, because it's not requred there, and leave it only for api calls. With this patch we also remove two unnecessary auxiliary functions from db api: _get_collection_sorted_by_time and _get_collection_sorted_by_name. Currently they are used to specify default parameters for 'sort_keys', but unfortunately they do it wrong, which leads to confusion and incorrect behavior of the system, when _get_collection_sorted_by_name is used to sort by time [1], when mutable is passed as a default parameter value and then modified in the code[2][3] (this is one of the most famous python anti-patterns [4]). To cope with non-determinism in tests instead of assertEqual method we use _assert_single_item, which allows to check results regardless of their order. Therefore, the patch allows to increase the performance of Mistral and make the code cleaner. [1] https://github.com/openstack/mistral/blob/stable/pike/mistral/db/v2/sqlalchemy/api.py#L528-L539 [2] https://github.com/openstack/mistral/blob/stable/pike/mistral/db/v2/sqlalchemy/api.py#L235 [3] https://github.com/openstack/mistral/blob/stable/pike/mistral/db/v2/sqlalchemy/api.py#L183-L184 [4] https://docs.quantifiedcode.com/python-anti-patterns/correctness/mutable_default_value_as_argument.html Change-Id: Ib4380f883969cab4ab851cd910c830e5ce30dfe5 |
||
---|---|---|
.. | ||
v2 | ||
__init__.py |