Refactor read_preference to accept a dictionary instead of a ReadPreference instance.
This commit is contained in:
		| @@ -5,6 +5,8 @@ import itertools | |||||||
| import re | import re | ||||||
| import warnings | import warnings | ||||||
|  |  | ||||||
|  | from collections.abc import Mapping | ||||||
|  |  | ||||||
| from bson import SON, json_util | from bson import SON, json_util | ||||||
| from bson.code import Code | from bson.code import Code | ||||||
| import pymongo | import pymongo | ||||||
| @@ -1221,11 +1223,11 @@ class BaseQuerySet(object): | |||||||
|         :param read_concern: override ReplicaSetConnection-level |         :param read_concern: override ReplicaSetConnection-level | ||||||
|             preference. |             preference. | ||||||
|         """ |         """ | ||||||
|         if read_concern is not None and not isinstance(read_concern, ReadConcern): |         if read_concern is not None and not isinstance(read_concern, Mapping): | ||||||
|             raise TypeError("%r is not a read concern." % (read_concern,)) |             raise TypeError("%r is not a valid read concern." % (read_concern,)) | ||||||
|  |  | ||||||
|         queryset = self.clone() |         queryset = self.clone() | ||||||
|         queryset._read_concern = read_concern |         queryset._read_concern = ReadConcern(**read_concern) | ||||||
|         queryset._cursor_obj = None  # we need to re-create the cursor object whenever we apply read_concern |         queryset._cursor_obj = None  # we need to re-create the cursor object whenever we apply read_concern | ||||||
|         return queryset |         return queryset | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user