views:

117

answers:

1

This seemingly perfect Google App Engine code fails with a KindError.

# in a django project 'stars'
from google.appengine.ext import db

class User(db.Model):
    pass

class Picture(db.Model):
    user = db.ReferenceProperty(User)

user = User()
user.put()

picture = Picture()
picture.user = user
# ===> KindError: Property user must be an instance of stars_user

The exception is raised in google.appengine.ext.db.ReferenceProperty.validate:

def validate(self, value):
    ...
    if value is not None and not isinstance(value, self.reference_class):
      raise KindError('Property %s must be an instance of %s' %
                            (self.name, self.reference_class.kind()))
    ...
+1  A: 

Turns out that I was importing the model in admin.py as

from frontend.stars.models import Star

This line had contaminated the module namespace of Star and the isinstance query was failing.

>>> user.__class__
<class 'frontend.stars.models.User'>
>>> Picture.user.reference_class
<class 'stars.models.User'>
ento
Another example of why "equivalent" examples often aren't. And why it helps to test your example actually has the error you say it does. :)
Nick Johnson