Trouble deleting an entity from it's key (believed to be a unicode issue)

28 views
Skip to first unread message

Jory Pettit

unread,
Feb 22, 2017, 5:07:34 PM2/22/17
to Google App Engine

I am having trouble deleting entities from keys in the GAE using python/ndb. I am able to retrieve the entity (problem) key from the page, but cannot figure out how to get it to delete. The GAE support page says it's as simple as retrieving the key and then deleting it, as seen below.

problem = problem_key.get()
problem.key.delete()

But this is not working. I'm pretty sure the key is being obtained correctly. The HTML looks like

{%for problem in problems %}
    <tr>
        <td>{{ problem.tags }}</td>
        <td><script type="math/tex">{{ problem.content }}</script></td>
        <td>{{ problem.answer }}</td>
        <td>{{ problem.quiz }}</td>
        <td>{{ problem.id }}</td>
        <td>{{ problem.date }}</td>
        <form action="/deleteProblem" method="POST">
            <td><button type="submit" name="problem_key" value="{{ problem.key }}">Delete Problem</button></td> 
        </form>
    </tr>
{% endfor %}    

And my python code looks like:

class deleteHandler(BaseHandler):
    def post(self):
        prob_key = self.request.get('problem_key')
        problem = prob_key.get()
        problem.key.delete()
        self.redirect("/")

I'm getting:

problem = prob_key.get()     
AttributeError: 'unicode' object has no attribute 'get'

My best guess is that prob_key is getting assigned the actual unicode and so of course there is no get() method for it but I don't understand how to fix the problem based on Google's explanation of how it should function.

Jordan (Cloud Platform Support)

unread,
Feb 23, 2017, 1:01:39 PM2/23/17
to Google App Engine
Google Groups is meant for general product discussions. Coding questions are best asked on Stack Overflow

I see that you have already posted this exact question on Stack Overflow, and some of the community has already responded to you there. I therefore recommended that you continue your investigations there. 
Reply all
Reply to author
Forward
0 new messages