```python
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:
```python
self.assertEqual(
FileExtensionValidator(["jpg", "png", "txt"]),
FileExtensionValidator(["txt", "jpg", "png"]),
)
```
So I suggest comparing two extension arrays after sorting them.
--
Ticket URL: <https://code.djangoproject.com/ticket/34920>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> `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.
>
> ```python
> 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:
>
> ```python
> self.assertEqual(
> FileExtensionValidator(["jpg", "png", "txt"]),
> FileExtensionValidator(["txt", "jpg", "png"]),
> )
> ```
>
> So I suggest comparing two extension arrays after sorting them.
New description:
`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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34920#comment:1>
Comment (by ksg97031):
PR: https://github.com/django/django/pull/17398
--
Ticket URL: <https://code.djangoproject.com/ticket/34920#comment:2>
* owner: nobody => ksg97031
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34920#comment:3>
Old description:
> `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.
>
New description:
This test case failed:
--
Comment (by Tim Graham):
I'd think that validators that behave identically should be considered
equal. Did you run into a real-world bug with the current behavior?
--
Ticket URL: <https://code.djangoproject.com/ticket/34920#comment:4>