JackNova
JackNova

Reputation: 3931

appengine illegal key.path.element.type: __BlobInfo__ trying to delete blobstore values

I'm experiencing an error that doesn't happen when I test the application on my machine but only after deployment.

I have some pictures associated with a parent item in the datastore and I have set up a query that deletes both the parent item and related pictures: datastore and blobstore values

I have a base key that I use as ancestor for all my items:

def base_key(group = 'default'):
    return db.Key.from_path('my_items', group)

I get the parent item and his attachments

parent = Parent.by_keyname(s)
attachments = Attachment.by_parent_keyname(s)

here's the implementation of those queries:

@classmethod # in Parent class
    def by_keyname(cls, s):
        item_k = db.Key.from_path('Parent', s, parent=base_key())
        item= db.get(item_k)
        return item

@classmethod # in Attachment class
    def by_parent_keyname(cls, s):
        item_k= db.Key.from_path('Parent', s, parent=base_key())
        q = Attachment.all()
        q.ancestor(item_k)
        results = q.fetch(20)
        return results

after I got parent and attachments I instanciate a list with all the keys whose elements I have to remove from datastore and blobstore:

entities_to_delete = [parent.key()]
            for a in attachments:
                entities_to_delete.append(a.key())
                entities_to_delete.append(
                    db.Key.from_path('__BlobInfo__', str(a.blob.key())))

            db.delete(entities_to_delete)

and this works perfectly on my machine but after deployment, if I test this request handler I get a server error, here is the error I log:

appengine log

full size image

Upvotes: 0

Views: 432

Answers (1)

Dan Sanderson
Dan Sanderson

Reputation: 2111

It appears the development server and the live server have different ideas about what it means to delete a BlobInfo entity. The most direct fix is to call the Blobstore delete() method for the blob keys:

entities_to_delete = []
blobs_to_delete = []
for a in attachments:
    entities_to_delete.append(upload.key())
    blobs_to_delete.append(upload.blob.key())
db.delete(entities_to_delete)
blobstore.delete(blobs_to_delete)

There might still be a way to construct a BlobInfo key in a way that db.delete() will accept, but the code you borrowed from my code sample is indeed inaccurate. My apologies for the inconvenience, and thanks for asking me about it!

Upvotes: 1

Related Questions