philipn/django-rest-framework-filters

Filtering fields order changes every time in swagger

seifElislam opened this issue · 4 comments

I'm using drf-yasg swagger library. I wrote filter_class using django-rest-framework-filters filterset
. Every change in the code changes the filtering fields order in swagger.

screenshot from 2019-03-03 17-54-14

Hi @seifElislam. It's not really possible to help without more detail. I assume you're using Meta.fields with a dict? If not, can you provide more details? e.g., what was your filterset class was before and after the code changes?

well, sorry for being late, but I think this behavior occurs because I'm using an apache server for production for my django app. With every apache restart, the order of fields in generated swagger json file is changed. I think, it is related to how apache serve the projcet, what's your opinion?

It sounds like you're using Python 3 pre-3.6, which added insertion ordering to dicts. Before that, Python 3.3 enabled hash randomization, so the same dict contents would be ordered differently per-process. I assume Apache is just restarting the underlying Python process, which causes the dict to be ordered differently.

Can you provide a more complete example of the filterset? What's not clear to me is if this is an issue in the user code or if it's in the library's code.

I'm going to close this for now, as more information is needed. Happy to take a second look if you can provide a more complete test case that demonstrates the bug (preferably in the form of a PR).