views:

258

answers:

2

I have a table called Mytable in home/models.py and using django aep I reference is as Mytable.all().

It shows up in the Data Viewer as home_mytable

Now, for some urls within app.yaml I have a separate handler that processes these requests. (This is in fact a google wave robot handler).

Within this handler I want to reference the table home_mytable I do so by calling db.GqlQuery("SELECT * from home_mytable")

However something strange happens. I receive a KindError No implementation for kind home_mytable

I receive this sporadically though, sometimes It works just fine, I suspect that happens right after I call up a url that references this table from a django handler.

My questions are, how can I a) ensure that this error doesnt occur and b) programattically check what the available 'kinds' are so I can try and debug this

+1  A: 

App Engine Patch monkeypatches your models to have different kind names. Don't ask me why, but that's what it does. To fix things, you need to override the kind() class method in your models to make sure they always have the 'fixed' kind names, like this:

class MyTable(db.Model):
  @classmethod
  def kind(cls):
    return "home_mytable"
Nick Johnson
Well, it did not fix the problem. Note: In the view that I make the db.GqlQuery("SELECT * from home_mytable") call I DO NOT import the MyTable calls (bcoz that would bring in all of django etc). I simply import db and make the call. A naked call to this view raises a KindError. If a call were to be first made to a django view that references this model and than a call to this view seems to work.Any ideas??
molicule
BTW: my current workaround is to do a try: db.GqlQuery except: do an urlfetch. Besides running up the urlfetch quota it is also slow.
molicule
Ok, so what's happeninn is that as long as the model has been loaded in memory by a view, other views can find home_mytable. But if there is no activity and the memory is released naked calls to home_mytable don't work. The workaround is in the next comment.
molicule
The workaround is to a) include the def kind call in the MyTable class and b) instead of importing the model (which can't be done as this would need all of django etc) re-define the class MyTable in the naked view. Now, there was a referenceproperty here that needed the User class (which wud mean importing django aep etc), I changed user = db.ReferencePropert(User) to user = db.ReferenceProperty(collection_name="user_set") and now calls to db.GqlQuery("SELECT * from home_mytable") seem to work.
molicule
Yes, I assumed you were importing your models - if you don't, obviously it can't find them - I thought that went without saying.
Nick Johnson
A: 

could you share your code? are you just rewriting the class Model(db.Model) to let you access the model? thats it?

Alon Carmel
when i redelcared my class name(db.Model) it fails to pull the data. doesnt pull data from the datastore for some reason. seems like its looking for a model called name when django creates the entities as name_name. do you suggest i redeclare the model as the django name?
Alon Carmel
I'm not using app engine patch anymore so don't have code to share. In your case you may want to check that the model is being redeclared within the same app as django creates entities as app_name
molicule
thanks. with what are you working now? django norel?
Alon Carmel