Skip to content

Atomic update affected by min_value validation #2403

Closed

Description

@StoneMoe

import unittest
from mongoengine import *

class User(DynamicDocument):
    level = IntField(required=True, min_value=0, default=0)


class Test(unittest.TestCase):
    def setUp(self) -> None:
        connection = connect(db='mongotest', host='mongomock://localhost')

    def test(self):
        a = User().save()
        self.assertEqual(0, a.level)

        a.update(inc__level=1)
        a.update(inc__level=1)
        a.reload()
        self.assertEqual(2, a.level)

        a.update(inc__level=-1)  # RAISE HERE: mongoengine.errors.ValidationError: Integer value is too small
        self.assertEqual(1, a.level)
        

if __name__ == "__main__":
    suite = unittest.defaultTestLoader.loadTestsFromTestCase(Test)
    unittest.TextTestRunner().run(suite)

Is this expected behavior or a bug?

Activity

  1. StoneMoe commented on Oct 29, 2020

    @StoneMoe
    Author

    Duplicate with #2339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions