MongoEngine / MongoEngine/mongoengine

Updating fields named 'size'

Open
#2,080 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

Greetings!

I've greatly enjoyed using MongoEngine :) One weird thing that's happened to me is that, upon defining a document with a field named 'size,' I'm unable to use .update(set__size=value). Here's an example:

class MyDoc(mongoengine.Document):
   size = mongoengine.IntField()

mine = MyDoc()
mine.size = 42
mine.save()

MyDoc.objects.update(set__size=0)

Upon executing the above, I receive the following error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/mongoengine/queryset/base.py", line 518, in update
    update = transform.update(queryset._document, **update)
  File "/usr/local/lib/python3.6/dist-packages/mongoengine/queryset/transform.py", line 276, in update
    field = cleaned_fields[-1]
  IndexError: list index out of range

This does not happen with Int fields named something else.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example, then inspect queryset/base.py and queryset/transform.py around the update path and the failing line 276. Confirm that updating a field named size succeeds and add a regression test covering the demonstrated MyDoc update.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.