I am new with developing web applications with Google App Engine.
I wanted to check for entities in my datastore which have a null value set for a list property (db.ListProperty
). However, when I tried to check anything against the entity.list
GAE gives the error:
'super' object has no attribute 'list'
.
After some search I saw in this SO question that setting an empty value for a list property of a GAE datastore entity is equivalent to not setting the property at all. This explains my error.
So I need to match entities in the datastore which do not have any list
property set at all. Looking at the GAE documentation I still haven't found any method which allows me to check whether an entity has a particular property set.
NOTE: I don't have to do this with GQL. I can retrieve all entities with GQL, then check with python. But a GQL solution is also fine.
I can think of three ways around this.
You're probably running into this situation because originally your model did not have a 'list' attribute, and you added one later, so you might have older instances in the datastore without the 'list' attribute. You can write a mapreduce function that goes through your datastore and ensures all entities have the 'list' element.
Otherwise, you can use the python hasattr function
if hasattr(entity, 'list'):
a = entity.list[0] # or whatever operation you want
Thirdly, you can use an exception handler to catch the error case.
There is no way to do this in GQL, which can only filter on existing values. Instead, you should use some form of computed property. NDB supports these, or you can override the _pre_put hook to have some other property set to be, for example, the length of the list. This will allow you to query on this new property == 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With