Hi,
I am having problems using isinstance to check the type of PolyModel
entities returned from Model.all().
Here is my type hierarchy:
google.appengine.ext.db.polymodel
model.Participant
model.StudentParticipant
model.FamilyMemberParticipant
model.TeacherParticipant
My files are laid out as follows:
app_id/
app.yaml
model.py
admin/
__init__.py
Home.py
app.yaml:
[...]
handlers:
- url: /admin(.*)
script: admin/__init__.py
app_id/__init__.py contains:
import Home
application = webapp.WSGIApplication([
('/admin', Home.Handler),
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()
Home.py has something like this:
import module
# ...
ps = model.Participant.all()
for p in ps:
... isinstance(p, model.StudentParticipant) ...
... isinstance(p, model.FamilyMemberParticipant) ...
... isinstance(p, model.TeacherParticipant) ...
This works only intermittently. Immediately after I update a new
version of my app, it works. Some time after (on the order of minutes
to hours, I have not investigated the exact amount of time), all of
the isinstance() calls return False.
I added some logging code to catch type(p), id(type(p)),
model.StudentParticipant, id(model.StudentParticipant), etc. When it
is working, the outputs agree. When it is not working (isinstance
returns False in all cases), the output is:
p: <model.StudentParticipant object at 0x76c1a0a1ff7dda8>
type(p): <class 'model.StudentParticipant'> @76c1a0a1118f298
model.StudentParticipant: <class '__main__.model.StudentParticipant'>
@76c1a0a111c5a98
model.FamilyMemberParticipant: <class
'__main__.model.FamilyMemberParticipant'> @76c1a0a111c5698
model.TeacherParticipant: <class '__main__.model.TeacherParticipant'>
@76c1a0a111c5298
Note how the types, when referenced using "model.XParticipant", are
also qualified using __main__. However, the type of the datastore
entities is the simple "model.XParticipant" name. The object IDs
(addresses) also differ.
I can only suspect that this is related to module caching on the App
Engine side. This has never occurred on the SDK. Without more
information about how App Engine does module caching, I can't debug
this further. Can anyone weigh in on this and any other ideas?
Thanks,
Catalin
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.