Compare commits

..

7 Commits

Author SHA1 Message Date
Stefan Wojcik
70f1067470 more thorough and isolated unit tests 2017-02-08 00:05:19 -08:00
Stefan Wojcik
fba4477dd8 fix flake8 2017-02-07 23:51:38 -08:00
Stefan Wojcik
6ac7a8eec6 fix chaining of the limit, skip, hint, and batch_size 2017-02-07 23:43:46 -08:00
Stefan Wojcik
bad4e6846a Cleaner ordering code + allow clearing an explicit sort 2017-02-07 23:38:56 -08:00
Stefan Wojcik
0e77efb0c7 Fix BaseQuerySet.comment 2017-02-07 23:34:39 -08:00
Stefan Wojcik
8a6f36256e minor cleanup 2017-02-06 19:29:35 -07:00
Stefan Wojcik
515ffac246 unit test showing issues with skip & limit on an existing queryset 2017-02-06 18:55:15 -07:00
4 changed files with 4 additions and 39 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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))

View File

@@ -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.