Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Changes in 1.0.0
- Fixed stacklevel of many warnings (to point places emitting the warning more accurately)
- Add support for collation/hint/comment to delete/update and aggregate #2842
- BREAKING CHANGE: Remove LongField as it's equivalent to IntField since we drop support to Python2 long time ago (User should simply switch to IntField) #2309
- BugFix - Prevent ``repr()`` from rewinding an actively iterated ``QuerySetNoCache`` #2870
- Replace MongoEngine-created ``bson.SON`` objects with built-in dictionaries, SON providing no advantages since Python 3.7 as native dict preserved insertion order. #2898
- BREAKING CHANGE: The obsolete ``slaves`` and ``is_slave`` connection options were silently ignored since 2014 and will now raise ``ConnectionFailure`` if provided #2920.
- BugFix - Calling .clear on a ListField wasn't being marked as changed (and flushed to db upon .save()) #2858
Expand Down
1 change: 1 addition & 0 deletions mongoengine/queryset/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,5 @@ def __iter__(self):
if queryset._iter:
queryset = self.clone()
queryset.rewind()
queryset._iter = True
return queryset
7 changes: 3 additions & 4 deletions tests/fields/test_decimal128_field.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import random
from decimal import Decimal

import pytest
Expand Down Expand Up @@ -142,8 +141,8 @@ def test_storage(self):

def test_json(self):
Decimal128Document.drop_collection()
f = str(random.random())
Decimal128Document(dec128_fld=f).save()
value = "9.549665900909776e-05"
Decimal128Document(dec128_fld=value).save()
json_str = Decimal128Document.objects.to_json()
array = json.loads(json_str)
assert array[0]["dec128_fld"] == {"$numberDecimal": str(f)}
assert array[0]["dec128_fld"] == {"$numberDecimal": "0.00009549665900909776"}
31 changes: 31 additions & 0 deletions tests/queryset/test_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5590,6 +5590,37 @@ class Person(Document):
qs = Person.objects.no_cache()
assert repr(qs) == "[]"

def test_queryset_repr__not_iterated__lists_documents(self):
class Person(Document):
name = StringField()

def __repr__(self):
return f"<Person: {self.name}>"

Person.drop_collection()
Person.objects.insert([Person(name="a"), Person(name="b")])

querysets = (
Person.objects.order_by("name"),
Person.objects.order_by("name").no_cache(),
)
for queryset in querysets:
with self.subTest(queryset_type=type(queryset).__name__):
assert repr(queryset) == "[<Person: a>, <Person: b>]"

def test_no_cached_queryset_repr__during_iteration__reports_without_rewinding(self):
class Person(Document):
name = StringField()

Person.drop_collection()
Person.objects.insert([Person(name="a"), Person(name="b")])
qs = Person.objects.order_by("name").no_cache()
iterator = iter(qs)

assert next(iterator).name == "a"
assert repr(qs) == ".. queryset mid-iteration .."
assert next(iterator).name == "b"

def test_no_cached_on_a_cached_queryset_raise_error(self):
class Person(Document):
name = StringField()
Expand Down