-
Couldn't load subscription status.
- Fork 1.2k
Bug fixed accessing BaseList with negative indices #1270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @Neurostack. Thank you for your contribution. I let the maintainers with deeper knowledge of MongoEngine discuss whether this is the best solution to address this issue. Just two questions:
Thanks again. |
|
|
|
OK so maybe you could add a new function around here that would look like this: def test_ListField_with_negative_indices(self):
class DocumentWithList(Document):
mylist = ListField()
test = DocumentWithList()
test.mylist = [1,2,3]
test.save()
test.mylist[-1] = 4
test.save() |
Most probably. I relaunched the build.
Looks fine to me. Maybe change into for consistency. @MongoEngine/mongoengine, any thoughts about this? |
|
@lafrech sure, all code should follow pep8 ;-) |
|
I meant "what do you guys think about the whole PR ?", not about that function name. Travis check passed, BWT. |
|
@thedrow, the idea is that when updating a list field using negative indexes like this:
and then when saving the doc, you get an exception. The change makes sure that Indeed, in mongo shell, I can do: but not: I get something like: As far as I could understand, this seems like the right place to address this issue. @Neurostack,before integration into master
|
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.
|
All small changes have been made and I cleaned up the test case in the process. The PR has been rebased into one commit and CI passes. Let me know if you need anything else. |
If you
__setitem__in BaseList with a negative index and then try to save this, you will get an error like:To fix this I rectify negative list indices in BaseList _mark_as_changed as the appropriate positive index. This fixes the above error.
This change is