Fixed bug accessing ListField (BaseList) with negative indices
If you __setitem__ in BaseList with a negative index and then try to save this, you will get an error like: OperationError: Could not save document (cannot use the part (shape of signal.shape.-1) to traverse the element ({shape: [ 0 ]})). To fix this I rectify negative list indices in BaseList _mark_as_changed as the appropriate positive index. This fixes the above error.
This commit is contained in:
committed by
Joshua Nedrud
parent
3b1509f307
commit
00430491ca
@@ -1160,6 +1160,19 @@ class FieldTest(unittest.TestCase):
|
||||
simple = simple.reload()
|
||||
self.assertEqual(simple.widgets, [4])
|
||||
|
||||
def test_list_field_with_negative_indices(self):
|
||||
|
||||
class Simple(Document):
|
||||
widgets = ListField()
|
||||
|
||||
simple = Simple(widgets=[1, 2, 3, 4]).save()
|
||||
simple.widgets[-1] = 5
|
||||
self.assertEqual(['widgets.3'], simple._changed_fields)
|
||||
simple.save()
|
||||
|
||||
simple = simple.reload()
|
||||
self.assertEqual(simple.widgets, [1, 2, 3, 5])
|
||||
|
||||
def test_list_field_complex(self):
|
||||
"""Ensure that the list fields can handle the complex types."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user