2
votes

I'm having a weird error with some Google App Engine code I'm writing.

My program contains some code like this:

import datetime

...

class Action(db.Model):
    visibleDate = db.DateTimeProperty()

...

getActionQuery = Action.gql("WHERE user = :user AND __key__ = :key", user = user, key = self.request.get("key"))
theAction = getActionQuery.get()

....

theAction.visibleDate = datetime.datetime.strptime(self.request.get("visibleDate"), "%Y/%m/%d")

Yet this produces the following error:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 509, in __call__
    handler.post(*groups)
  File "/Users/redbird/Developer/betterdo-it/main.py", line 132, in post
    theAction.visibleDate = datetime.datetime.strptime(self.request.get("visibleDate"), "%Y/%m/%d"),
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 472, in __set__
    value = self.validate(value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2308, in validate
    (self.name, self.data_type.__name__))
BadValueError: Property visibleDate must be a datetime

Any ideas on why this is happening? I've tested it and I know that my time is coming in, is getting converted correctly, but then hits this error.

1
Perhaps the date is not well formatted? What does self.request.get("visibleDate") returns?jbochi
Shouldn't it be visibleDate = db.DateTimeProperty() in model's definition?jbochi
It is; just a typo. I fixed it.G Gordon Worley III
self.request.get("visibleDate") = "2010/01/01"G Gordon Worley III
How odd. What about type(datetime.datetime.strptime(self.request.get("visibleDate"), "%Y/%m/%d"))?jbochi

1 Answers

5
votes

I think there's something you missed in your traceback.

I'm seeing:datetime.datetime.strptime(self.request.get("visibleDate"), "%Y/%m/%d"),

Notice the comma at the end of the line.

That comma makes that line return a tuple with your date inside it. I'm assuming you accidentally added the comma, so just remove it and you should be correctly assigning a datetime.

To review:

from datetime import datetime
a = (datetime(2000,1,1),)
assert isinstance(a, tuple)
a = (datetime(2000,1,1))
assert isinstance(a, datetime)