Fix issues with App Engine datastore
diff --git a/Makefile b/Makefile
index f53fa87..f1bf782 100644
--- a/Makefile
+++ b/Makefile
@@ -27,8 +27,8 @@
 	@echo "Here we go..."
 	cd snapshot; python setup.py sdist --formats=gztar,zip register upload
 	wget "http://support.googlecode.com/svn/trunk/scripts/googlecode_upload.py" -O googlecode_upload.py
-	python googlecode_upload.py --summary="Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.tar.gz
-	python googlecode_upload.py --summary="Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.zip
+	python googlecode_upload.py --summary="google-api-python-client Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.tar.gz
+	python googlecode_upload.py --summary="google-api-python-client Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.zip
 
 
 .PHONY: oauth2_prerelease
@@ -56,5 +56,5 @@
 	@echo "Here we go..."
 	cd snapshot; python setup.py sdist --formats=gztar,zip register upload
 	wget "http://support.googlecode.com/svn/trunk/scripts/googlecode_upload.py" -O googlecode_upload.py
-	python googlecode_upload.py --summary="Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.tar.gz
-	python googlecode_upload.py --summary="Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.zip
+	python googlecode_upload.py --summary="oauth2client Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.tar.gz
+	python googlecode_upload.py --summary="oauth2client Version $(shell python setup.py --version)" --project=google-api-python-client snapshot/dist/*.zip
diff --git a/oauth2client/appengine.py b/oauth2client/appengine.py
index 68d5066..533d53f 100644
--- a/oauth2client/appengine.py
+++ b/oauth2client/appengine.py
@@ -19,10 +19,11 @@
 
 __author__ = 'jcgregorio@google.com (Joe Gregorio)'
 
+import base64
 import httplib2
+import logging
 import pickle
 import time
-import base64
 
 try: # pragma: no cover
   import simplejson
@@ -152,7 +153,7 @@
 
   def validate(self, value):
     if value is not None and not isinstance(value, Flow):
-      raise BadValueError('Property %s must be convertible '
+      raise db.BadValueError('Property %s must be convertible '
                           'to a FlowThreeLegged instance (%s)' %
                           (self.name, value))
     return super(FlowProperty, self).validate(value)
@@ -173,6 +174,7 @@
 
   # For writing to datastore.
   def get_value_for_datastore(self, model_instance):
+    logging.info("get: Got type " + str(type(model_instance)))
     cred = super(CredentialsProperty,
                  self).get_value_for_datastore(model_instance)
     if cred is None:
@@ -183,6 +185,8 @@
 
   # For reading from datastore.
   def make_value_from_datastore(self, value):
+    logging.info("make: Got a " + value)
+    logging.info("make: Got type " + str(type(value)))
     if value is None:
       return None
     if len(value) == 0:
@@ -191,18 +195,22 @@
     try:
       credentials = Credentials.new_from_json(value)
     except ValueError:
-      credentials = pickle.loads(value)
+      try:
+        credentials = pickle.loads(value)
+      except ValueError:
+        credentials = None
     return credentials
 
   def validate(self, value):
+    value = super(CredentialsProperty, self).validate(value)
+    logging.info("validate: Got type " + str(type(value)))
     if value is not None and not isinstance(value, Credentials):
       raise db.BadValueError('Property %s must be convertible '
-                          'to an Credentials instance (%s)' %
-                          (self.name, value))
-    return super(CredentialsProperty, self).validate(value)
-
-  def empty(self, value):
-    return not value
+                          'to a Credentials instance (%s)' %
+                            (self.name, value))
+    #if value is not None and not isinstance(value, Credentials):
+    #  return None
+    return value
 
 
 class StorageByKeyName(Storage):
diff --git a/oauth2client/client.py b/oauth2client/client.py
index 2b97d4d..6392533 100644
--- a/oauth2client/client.py
+++ b/oauth2client/client.py
@@ -44,7 +44,7 @@
 logger = logging.getLogger(__name__)
 
 # Expiry is stored in RFC3339 UTC format
-EXPIRY_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
+EXPIRY_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
 
 
 class Error(Exception):
@@ -283,8 +283,11 @@
     data = simplejson.loads(s)
     if 'token_expiry' in data and not isinstance(data['token_expiry'],
         datetime.datetime):
-      data['token_expiry'] = datetime.datetime.strptime(
-          data['token_expiry'], EXPIRY_FORMAT)
+      try:
+        data['token_expiry'] = datetime.datetime.strptime(
+            data['token_expiry'], EXPIRY_FORMAT)
+      except:
+        data['token_expiry'] = None
     retval = OAuth2Credentials(
         data['access_token'],
         data['client_id'],
diff --git a/samples/appengine_with_decorator2/app.yaml b/samples/appengine_with_decorator2/app.yaml
index c0d43d5..bdc4be1 100644
--- a/samples/appengine_with_decorator2/app.yaml
+++ b/samples/appengine_with_decorator2/app.yaml
@@ -1,5 +1,5 @@
 application: jcg-testing-01
-version: 1
+version: 2
 runtime: python
 api_version: 1
 
diff --git a/samples/appengine_with_decorator2/main.py b/samples/appengine_with_decorator2/main.py
index 4cd2401..05fa922 100644
--- a/samples/appengine_with_decorator2/main.py
+++ b/samples/appengine_with_decorator2/main.py
@@ -41,8 +41,8 @@
 # The client_id and client_secret are copied from the API Access tab on
 # the Google APIs Console <http://code.google.com/apis/console>
 decorator = OAuth2Decorator(
-    client_id='837647042410-75ifgipj95q4agpm0cs452mg7i2pn17c.apps.googleusercontent.com',
-    client_secret='QhxYsjM__u4vy5N0DXUFRwwI',
+    client_id='837647042410-49mlotv28bfpn5a0igtinipsb8so5eob.apps.googleusercontent.com',
+    client_secret='d4BSDjl4rmFmk-wh28_aK1Oz',
     scope='https://www.googleapis.com/auth/buzz')
 
 http = httplib2.Http(memcache)
diff --git a/tests/test_oauth2client.py b/tests/test_oauth2client.py
index 14beb97..4063e8b 100644
--- a/tests/test_oauth2client.py
+++ b/tests/test_oauth2client.py
@@ -101,6 +101,9 @@
     json = self.credentials.to_json()
     instance = OAuth2Credentials.from_json(json)
     self.assertEquals(type(instance), OAuth2Credentials)
+    instance.token_expiry = None
+    self.credentials.token_expiry = None
+
     self.assertEquals(self.credentials.__dict__, instance.__dict__)