hmarr/mongoengine — Issue #351: docs and code differ on "choices" parameter
Author: aparrish
Created: 2011-11-08 23:01:06+00:00
State: open

From the documentation:

choices (Default: None)
An iterable of choices to which the value of this field should be limited.

From the source code:

def _validate(self, value):
# check choices
if self.choices is not None:
option_keys = [option_key for option_key, option_value in self.choices]
if value not in option_keys:
raise ValidationError("Value must be one of %s." % unicode(option_keys))

The documentation implies I can write something like this:

class Foo(Document):
status = StringField(choices=["bar", "baz", "quux"])

... but the source code requires me to write something like this:

class Foo(Document):
status = StringField(choices=[('bar', 1), ('baz', 1), ('quux', 1)])

Or am I missing something? what is the deal y'all