Hi

Have a look at the basic Model definition from the docs.

class Model(parent=None, key_name=None, **kwds):
   ...

Note the first argument is the parent, the second is the key_name

You offending code is doing

activity = models.Activity(actor, object, action='upvote')

When it should be

activity = models.Activity(actor, object.<some method that provides a
name>, action='upvote')

Assuming actor is the parent, and object provides a key_name, or
alternately
you can construct a key entity and pass it in as key=<my key entity>.

Not knowing what you original intent for object is in the construction
of the key for an Actor
means I am not sure about specifically what you should be providing to
construct the key.

In the end the error is telling you exactly what is going on ;-)

Rgds

T

On Jul 2, 2:43 am, daveying99 <david.had...@gmail.com> wrote:
> Hey everyone. I am using Appengine/Python and I haven't been able to
> fix a BadKeyError bug for the last 5 hours. I'm wondering if someone
> can help me figure it out. The part of the app that is causing the bug
> is a controller that processes votes done by users. Actor_id is the
> key of the user and object_id is the key of the object that is being
> voted on.
>
> I've been testing the app by hiding and restoring some code, and I
> know for sure that the keys being received are good (first block), and
> that the entities are being created (second block). What does not work
> is creating an activity instance - raises BadKeyError (third block)
>
> I've added the controller code, the model code, and the traceback of
> the error from the log page.
>
> ******* Controller Code *******
> # /addactivity?person=xxx&object=yyy
> class ActivityHandler(FacebookEnabled):
>         def get(self):
>
>                 # i.e. fbid / headline id / upvote. This works
>                 actor_id = self.request.get('actor_id')
>                 object_id = self.request.get('object_id')
>                 action = self.request.get('action')
>
>                 # creating actor and object from keys (actor_id and 
> object_id). This
> works.
>                 actor = models.Person.get(actor_id)
>                 object = models.Headline.get(object_id)
>                 logging.info("Actor " + str(actor) +": " + str(actor.name) + "
> object " + str(object) + ": " + str(object.title))
>
>                 # THIS IS WHAT SEEMS TO RAISE AN EXCEPTION
>                 activity = models.Activity(actor, object, action='upvote')
>                 activity.put()
>
> ******* Model Code *******
> class Activity(polymodel.PolyModel):
>
>         # User causing the action i.e. a person
>         actor = db.ReferenceProperty(Person, required=True,
> collection_name='actors')
>
>         # The object being the subject of the action i.e. headline
>         object = db.ReferenceProperty(Headline, required=True,
> collection_name='objects')
>
>         # The action being made
>         action = db.StringProperty(required=True, choices=['upvote',
> 'downvote'], default='upvote')
>
> ******* Traceback *******
> Name must be string type, not Headline
> Traceback (most recent call last):
>   File "/base/python_runtime/python_lib/versions/1/google/appengine/
> ext/webapp/__init__.py", line 511, in __call__
>     handler.get(*groups)
>   File "/base/data/home/apps/libnentest/2.343063076026692316/main.py",
> line 125, in get
>     activity = models.Activity(actor, object, action='upvote')
>   File "/base/python_runtime/python_lib/versions/1/google/appengine/
> ext/db/__init__.py", line 726, in __init__
>     key_name.__class__.__name__)
> BadKeyError: Name must be string type, not Headline

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to