Compare commits
7 Commits
field-choi
...
fix-cursor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70f1067470 | ||
|
|
fba4477dd8 | ||
|
|
6ac7a8eec6 | ||
|
|
bad4e6846a | ||
|
|
0e77efb0c7 | ||
|
|
8a6f36256e | ||
|
|
515ffac246 |
@@ -5,8 +5,6 @@ Changelog
|
|||||||
Development
|
Development
|
||||||
===========
|
===========
|
||||||
- (Fill this out as you fix issues and develop you features).
|
- (Fill this out as you fix issues and develop you features).
|
||||||
- POTENTIAL BREAKING CHANGE: Fixed limit/skip/hint/batch_size chaining #1476
|
|
||||||
- POTENTIAL BREAKING CHANGE: Changed a public `QuerySet.clone_into` method to a private `QuerySet._clone_into` #1476
|
|
||||||
- Fixed connecting to a replica set with PyMongo 2.x #1436
|
- Fixed connecting to a replica set with PyMongo 2.x #1436
|
||||||
- Fixed an obscure error message when filtering by `field__in=non_iterable`. #1237
|
- Fixed an obscure error message when filtering by `field__in=non_iterable`. #1237
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,6 @@
|
|||||||
Upgrading
|
Upgrading
|
||||||
#########
|
#########
|
||||||
|
|
||||||
Development
|
|
||||||
***********
|
|
||||||
(Fill this out whenever you introduce breaking changes to MongoEngine)
|
|
||||||
|
|
||||||
This release includes various fixes for the `BaseQuerySet` methods and how they
|
|
||||||
are chained together. Since version 0.10.1 applying limit/skip/hint/batch_size
|
|
||||||
to an already-existing queryset wouldn't modify the underlying PyMongo cursor.
|
|
||||||
This has been fixed now, so you'll need to make sure that your code didn't rely
|
|
||||||
on the broken implementation.
|
|
||||||
|
|
||||||
Additionally, a public `BaseQuerySet.clone_into` has been renamed to a private
|
|
||||||
`_clone_into`. If you directly used that method in your code, you'll need to
|
|
||||||
rename its occurrences.
|
|
||||||
|
|
||||||
0.11.0
|
0.11.0
|
||||||
******
|
******
|
||||||
This release includes a major rehaul of MongoEngine's code quality and
|
This release includes a major rehaul of MongoEngine's code quality and
|
||||||
|
|||||||
@@ -189,18 +189,14 @@ class BaseField(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _validate_choices(self, value):
|
def _validate_choices(self, value):
|
||||||
"""Validate that value is a valid choice for this field."""
|
|
||||||
Document = _import_class('Document')
|
Document = _import_class('Document')
|
||||||
EmbeddedDocument = _import_class('EmbeddedDocument')
|
EmbeddedDocument = _import_class('EmbeddedDocument')
|
||||||
|
|
||||||
# Field choices can be given as an iterable (e.g. tuple/list/set) of
|
|
||||||
# values or an iterable of value-label pairs, e.g. ('XS', 'Extra Small').
|
|
||||||
# It the latter case, extract just the values for comparison.
|
|
||||||
choice_list = self.choices
|
choice_list = self.choices
|
||||||
if isinstance(next(iter(choice_list)), (list, tuple)):
|
if isinstance(choice_list[0], (list, tuple)):
|
||||||
choice_list = [val for val, label in choice_list]
|
choice_list = [k for k, _ in choice_list]
|
||||||
|
|
||||||
# Validate Document/EmbeddedDocument choices
|
# Choices which are other types of Documents
|
||||||
if isinstance(value, (Document, EmbeddedDocument)):
|
if isinstance(value, (Document, EmbeddedDocument)):
|
||||||
if not any(isinstance(value, c) for c in choice_list):
|
if not any(isinstance(value, c) for c in choice_list):
|
||||||
self.error(
|
self.error(
|
||||||
@@ -208,8 +204,7 @@ class BaseField(object):
|
|||||||
six.text_type(choice_list)
|
six.text_type(choice_list)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# Choices which are types other than Documents
|
||||||
# Validate any other type of choices
|
|
||||||
elif value not in choice_list:
|
elif value not in choice_list:
|
||||||
self.error('Value must be one of %s' % six.text_type(choice_list))
|
self.error('Value must be one of %s' % six.text_type(choice_list))
|
||||||
|
|
||||||
|
|||||||
@@ -3205,22 +3205,8 @@ class FieldTest(unittest.TestCase):
|
|||||||
shirt.size = "XS"
|
shirt.size = "XS"
|
||||||
self.assertRaises(ValidationError, shirt.validate)
|
self.assertRaises(ValidationError, shirt.validate)
|
||||||
|
|
||||||
def test_choices_as_set(self):
|
|
||||||
"""Ensure that sets can be used as field choices"""
|
|
||||||
class Shirt(Document):
|
|
||||||
size = StringField(choices={'S', 'M', 'L', 'XL', 'XXL'})
|
|
||||||
|
|
||||||
Shirt.drop_collection()
|
Shirt.drop_collection()
|
||||||
|
|
||||||
shirt = Shirt()
|
|
||||||
shirt.validate()
|
|
||||||
|
|
||||||
shirt.size = "S"
|
|
||||||
shirt.validate()
|
|
||||||
|
|
||||||
shirt.size = "XS"
|
|
||||||
self.assertRaises(ValidationError, shirt.validate)
|
|
||||||
|
|
||||||
def test_choices_validation_documents(self):
|
def test_choices_validation_documents(self):
|
||||||
"""
|
"""
|
||||||
Ensure fields with document choices validate given a valid choice.
|
Ensure fields with document choices validate given a valid choice.
|
||||||
|
|||||||
Reference in New Issue
Block a user