Skip to content
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

ListField minus index assignment does not work #1119

Closed
iici-gli opened this issue Sep 30, 2015 · 1 comment
Closed

ListField minus index assignment does not work #1119

iici-gli opened this issue Sep 30, 2015 · 1 comment
Labels

Comments

@iici-gli
Copy link
Contributor

iici-gli commented Sep 30, 2015

class Foo(Document):
  a_str = StringField()
  a_list_str = ListField(StringField())

foo = Foo(a_str='a', a_list_str=['1','2','3'])
foo.save()
foo.a_list_str[-1] = '4'
foo.save()

foo = Foo.objects(a_str='a').as_pymongo().first()
print foo['a_list_str'][-1] 

=> ['1', '2', '4']
The last element becomes list itself

The bug is in file mongoengine/base/document at line 644:

     if isinstance(d, list) and p.isdigit():

It should be:

    if isinstance(d, list) and p.lstrip('-').isdigit(): 
iici-gli added a commit to iici-gli/mongoengine that referenced this issue Oct 12, 2015
Add code to detect '-1' as a integer.
Normalize negative index to regular list index
Added list assignment test case
iici-gli added a commit to iici-gli/mongoengine that referenced this issue Oct 18, 2015
@lafrech lafrech added the Bug label Mar 23, 2016
lafrech added a commit that referenced this issue Sep 7, 2016
Fixed: ListField minus index assignment does not work #1119
@wojcikstefan
Copy link
Member

This issue was fixed by #1435. I added an extra test for this behavior in e8ea294.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants