Opened 18 months ago
Last modified 18 months ago
#34920 closed Bug
Reordered file extensions for improved validation — at Version 4
Description (last modified by ) ¶
django.core.validators.FileExtensionValidator
had an __eq__
method to compare the validator class. However, comparing arrays is not accurate when the order of elements in the arrays is different.
def __eq__(self, other): return ( isinstance(other, self.__class__) and sorted(self.allowed_extensions) == sorted(other.allowed_extensions) and self.message == other.message and self.code == other.code )
This test case failed:
self.assertEqual( FileExtensionValidator(["jpg", "png", "txt"]), FileExtensionValidator(["txt", "jpg", "png"]), )
So I suggest comparing two extension arrays after sorting them.
Change History (4)
comment:1 by , 18 months ago
Description: | modified (diff) |
---|
comment:2 by , 18 months ago
comment:3 by , 18 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 18 months ago
Description: | modified (diff) |
---|
I'd think that validators that behave identically should be considered equal. Did you run into a real-world bug with the current behavior?
Note:
See TracTickets
for help on using tickets.
PR: https://github.com/django/django/pull/17398