I have a profile class:
class profile(db.Model):
user = db.stringProperty()
# Other properties ...
access = db.ListProperty(db.keys)
class apps(db.Model):
name = db.StringProperty()
The profile class was there for quiet some time, but we added recently access field which will store the keys of apps. Now we are adding profile permissions on the app, access field does not get updated in开发者_StackOverflow社区 the model.
This works fine totally on localhost, but when I update this on server I get this error "'NoneType' object has no attribute 'access'" Has anybody come across same situation
Update: Figured out that one of the object from profile class is being returned as None. Here is the code which gets profile object on localhost but None on the server
liuser = users.User(request.POST['user'])
#request.POST['user'] gets user Gmail ID, which is being converted to user object
profiles=Profile.all().filter(" user =", liuser).get()
userprofile=profiles
#tried below code which returns "'NoneType' object has no attribute 'access'" on server, the same gets a profile object on localhost
if not hasattr(userprofile, "access"):
userprofile.access=[]
@Robert hope the formatting is fine now.
Thank You Sai Krishna
We were able to fix this. The problem was with users.User object which does not append @gmail.com for gmail users, but while it accepts for other domains with domain name, which was throwing None Type object
Thank You once again for the help
When you add a property to a model, the existing instances of the model that are in the datastore do not automatically get that property.
You will need to modify your handler code that interacts with profile entities to check for the existence of access. Python's hasattr
function will do. Something like this:
a_profile = profile.all().somequerystuffheretogetaninstance().get()
if a_profile is not None:
if not hasattr(a_profile, "access"):
a_profile.access = whateveryourdefaultdatais
# perform my data logic normally after this, but remember to persist
# this to the datastore to save the new access property.
精彩评论