Open djlambert opened 1 year ago
I ran into this because a unittest was flaky. It's a bit annoying.
I ran into this because a unittest was flaky. It's a bit annoying.
That was the issue I was running into too
I think I wouldn't even have noticed, if the JsonPatch class had an equality comparison __eq__
which accounts for the fact that the order doesn't matter.
This is caused by the use of sets for comparing dict keys in the internals of the library. Sets (unlike dicts in newer versions of Python) do not preserve order. Ordering is determined by the hash values of objects within the set.
By default, Python randomizes hashes for security purposes. As a workaround for test cases you can disable this behavior by setting PYTHONHASHSEED=0
, but you should avoid doing this during actual execution to preserve the security benefits.
I've submitted #161 which I believe will address this issue without requiring PYTHONHASHSEED=0
.
On Python 3.6+ (where dict is ordered) I'd expected the following to always return the same results:
This isn't the case though: