storage: do not fail __repr__ for criterias without value (#57914)

This commit is contained in:
Frédéric Péters 2021-10-17 16:07:33 +02:00
parent 69640091e8
commit 713a6ccc82
2 changed files with 8 additions and 1 deletions

View File

@ -482,6 +482,9 @@ def test_criteria_repr():
assert 'foo' in repr(criteria)
assert 'bar' in repr(criteria)
criteria = wcs.qommon.storage.Null('foo')
assert 'Null' in repr(criteria)
def test_related_field_repr():
from wcs.backoffice.management import RelatedField

View File

@ -158,7 +158,11 @@ class Criteria:
return lambda x: self.op(getattr(x, self.attribute, None) or self.typed_none, self.value)
def __repr__(self):
return '<%s (attribute: %r, value: %r)>' % (self.__class__.__name__, self.attribute, self.value)
return '<%s (attribute: %r%s)>' % (
self.__class__.__name__,
self.attribute,
', value: %r' % self.value if hasattr(self, 'value') else '',
)
class Less(Criteria):