views:

322

answers:

1

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.

+3  A: 

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)

Chris S
Thanks, that was it. I was worried we were going crazy here.
Gordon Worley