benoitc/couchdbkit — Issue #114: Property timestamp must be a datetime, current is unicode
Author: eutheria
Created: 2012-01-08 13:27:40+00:00
State: open

I've created a Document class as so:

class Base(Document):
... doc_schema = IntegerProperty(required=True)
... name = StringProperty(required=True)
... update = DateTimeProperty(required=True, auto_now=True)
... created = DateTimeProperty(required=True, auto_now_add=True)

I have some json returned by a db.get(doc_id)

{u'created': u'2012-01-07T18:17:39Z',
u'doc_schema': 0,
u'doc_type': u'test',
u'name': u'abc',
u'update': u'2012-01-07T18:17:39Z'}

I've also tried db.open_doc()

>>> account = Base(some_json_doc)

Traceback (most recent call last):
File "", line 1, in
File "/home/user/env/local/lib/python2.7/site-packages/couchdbkit/schema/base.py", line 405, in __init__
DocumentSchema.__init__(self, _d, **kwargs)
File "/home/user/env/local/lib/python2.7/site-packages/couchdbkit/schema/base.py", line 113, in __init__
prop.__property_init__(self, value)
File "/home/user/env/local/lib/python2.7/site-packages/couchdbkit/schema/properties.py", line 95, in __property_init__
value = self.to_json(self.validate(value, required=False))
File "/home/user/env/local/lib/python2.7/site-packages/couchdbkit/schema/properties.py", line 304, in validate
(self.name, self.data_type.__name__, type(value).__name__))
couchdbkit.exceptions.BadValueError: Property update must be a datetime, current is unicode

having a little look at what was going on, it appears the validate method is being called before the to_python so yes it is a unicode string and not a datetime object