Merge pull request #2160 from vainu-arto/fix-trust-default-cursor-timeout

Only set no_cursor_timeout when requested
This commit is contained in:
Bastien Gérard 2019-09-11 22:09:56 +02:00 committed by GitHub
commit 6203e30152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -1577,7 +1577,10 @@ class BaseQuerySet(object):
if self._snapshot: if self._snapshot:
msg = "The snapshot option is not anymore available with PyMongo 3+" msg = "The snapshot option is not anymore available with PyMongo 3+"
warnings.warn(msg, DeprecationWarning) warnings.warn(msg, DeprecationWarning)
cursor_args = {"no_cursor_timeout": not self._timeout}
cursor_args = {}
if not self._timeout:
cursor_args["no_cursor_timeout"] = True
if self._loaded_fields: if self._loaded_fields:
cursor_args[fields_name] = self._loaded_fields.as_dict() cursor_args[fields_name] = self._loaded_fields.as_dict()

View File

@ -5809,9 +5809,19 @@ class TestQueryset(unittest.TestCase):
self.Person.objects.create(name="Baz") self.Person.objects.create(name="Baz")
self.assertEqual(self.Person.objects.count(with_limit_and_skip=True), 3) self.assertEqual(self.Person.objects.count(with_limit_and_skip=True), 3)
newPerson = self.Person.objects.create(name="Foo_1") self.Person.objects.create(name="Foo_1")
self.assertEqual(self.Person.objects.count(with_limit_and_skip=True), 4) self.assertEqual(self.Person.objects.count(with_limit_and_skip=True), 4)
def test_no_cursor_timeout(self):
qs = self.Person.objects()
self.assertEqual(qs._cursor_args, {}) # ensure no regression of #2148
qs = self.Person.objects().timeout(True)
self.assertEqual(qs._cursor_args, {})
qs = self.Person.objects().timeout(False)
self.assertEqual(qs._cursor_args, {"no_cursor_timeout": True})
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()