Reputation: 33
I am having a weird message error.
I have a model with a StringProperty
called checksum
, but when I try to save to it, I get a validation error claiming that a Key value was expected.
EDIT: to avoid potential issues i renamed the id
property to gdid
, as it is displayed now, and the error persists.
class gd_file(base_class):
"""Google Drive File Reference"""
gdid = ndb.StringProperty()
#creation_date = ndb.DateTimeProperty()
#modification_date = ndb.DateTimeProperty()
name = ndb.StringProperty()
checksum = ndb.StringProperty()
size = ndb.IntegerProperty()
office = ndb.KeyProperty()
parents = ndb.KeyProperty()
sample code:
logging.info('GD_FILE:')
for p in gd_file._properties:
logging.info( getattr(gd_file,p))
logging.info('m:')
logging.info(type(m))
logging.info(m)
fd = gd_file(
parents = parents_list,
owners = gd['ownerNames'],
last_changed_by = gd['lastModifyingUserName'],
creation_date = datetime.datetime.strptime(cdate, '%Y-%m-%d %H:%M:%S.%f'),
modification_date = datetime.datetime.strptime(mdate, '%Y-%m-%d %H:%M:%S.%f'),
gdid = gd['id'],
name = result['name'],
size = result['size'],
type = gd['mimeType'],
checksum = m
)
Line 231 in my code is where I attribute checksum = m
above.
Log including error:
INFO 2014-02-20 21:20:09,042 proterrahandler.py:213] GD_FILE:
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] KeyProperty('parents')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('checksum')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('owners', repeated=True)
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] DateTimeProperty('creation_date', auto_now_add=True)
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('type')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('last_changed_by')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('name')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] IntegerProperty('size')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] DateTimeProperty('modification_date', auto_now=True)
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] KeyProperty('cid')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] KeyProperty('office')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('id')
INFO 2014-02-20 21:20:09,042 proterrahandler.py:217] m:
INFO 2014-02-20 21:20:09,042 proterrahandler.py:218] <type 'str'>
INFO 2014-02-20 21:20:09,042 proterrahandler.py:219] 019f8998e5896bb34ecdbb0803343486
ERROR 2014-02-20 21:20:09,046 webapp2.py:1552] Expected Key, got [u'0B2PeVr8B69LER2ZGWVNjM29TSTQ']
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "C:\Users\Tiago\Google Drive\Development\gae\cert-id-tinkerbox\proterrahandler.py", line 89, in post
files = self.handle_upload()
File "C:\Users\Tiago\Google Drive\Development\gae\cert-id-tinkerbox\proterrahandler.py", line 231, in handle_upload
checksum = m
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 2852, in __init__
self._set_attributes(kwds)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 3587, in _set_attributes
setattr(self, name, value)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 3605, in __setattr__
return super(Expando, self).__setattr__(name, value)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1343, in __set__
self._set_value(entity, value)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1088, in _set_value
value = self._do_validate(value)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1035, in _do_validate
value = self._call_shallow_validation(value)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1227, in _call_shallow_validation
return call(value)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1274, in call
newvalue = method(self, value)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1927, in _validate
raise datastore_errors.BadValueError('Expected Key, got %r' % (value,))
BadValueError: Expected Key, got [u'0B2PeVr8B69LER2ZGWVNjM29TSTQ']
INFO 2014-02-20 18:20:09,193 module.py:612] default: "POST /app/proterra/checklist/import HTTP/1.1" 500 3357
I am a bit stumped on this one, I have no idea where the Key error is being raised.
Any ideas?
Upvotes: 0
Views: 974
Reputation: 12986
You can't have a property called id
It is a argument supplied to the constructor which is used in creating a Key with a supplied id.
Have a read of the ndb.Model docs https://developers.google.com/appengine/docs/python/ndb/modelclass#Constructor
Upvotes: 1