AttributeError: 'Entity' object has no attribute '_to_pb' when trying to finalize a blobstore file.

100 views
Skip to first unread message

wwwtyro

unread,
Jan 16, 2013, 7:48:48 AM1/16/13
to google-a...@googlegroups.com
I'm not sure what I am doing wrong here; my code is almost identical to the documentation example.

My code: 

    filename = files.blobstore.create(mime_type='application/octet-stream')
   
with files.open(filename, 'a') as f:
        f
.write(json.dumps(oldblocks, separators=(',', ':')))
    files
.finalize(filename)

Stack trace:

WARNING  2013-01-16 12:37:49,648 tasklets.py:409] suspended generator transaction(context.py:932) raised AttributeError('Entity' object has no attribute '_to_pb')
ERROR    2013-01-16 12:37:49,648 webapp2.py:1552] 'Entity' object has no attribute '_to_pb'
Traceback (most recent call last):
  File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/home/rye/Dropbox/projects/web/voxwright/voxwright.py", line 202, in put
    result = saveProject(data['id'], data['blocks'])
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 3583, in inner_transactional_wrapper
    return transaction(f, **ctx_options)
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/utils.py", line 136, in positional_wrapper
    return wrapped(*args, **kwds)
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 3526, in transaction
    return fut.get_result()
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
    self.check_success()
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/tasklets.py", line 371, in _help_tasklet_along
    value = gen.send(val)
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/context.py", line 923, in transaction
    result = callback()
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 3582, in <lambda>
    f = lambda: func(*args, **kwds)
  File "/home/rye/Dropbox/projects/web/voxwright/voxwright.py", line 102, in saveProject
    files.finalize(filename)
  File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 568, in finalize
    f.close(finalize=True)
  File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 291, in close
    self._make_rpc_call_with_retry('Close', request, response)
  File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 427, in _make_rpc_call_with_retry
    _make_call(method, request, response)
  File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 250, in _make_call
    rpc.check_success()
  File "/home/rye/local/share/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 570, in check_success
    self.__rpc.CheckSuccess()
  File "/home/rye/local/share/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl
    self.request, self.response)
  File "/home/rye/local/share/google_appengine/google/appengine/api/apiproxy_stub.py", line 125, in MakeSyncCall
    method(request, response)
  File "/home/rye/local/share/google_appengine/google/appengine/api/files/file_service_stub.py", line 652, in _Dynamic_Close
    self.open_files[filename].finalize()
  File "/home/rye/local/share/google_appengine/google/appengine/api/files/file_service_stub.py", line 596, in finalize
    datastore.Put(blob_info)
  File "/home/rye/local/share/google_appengine/google/appengine/api/datastore.py", line 579, in Put
    return PutAsync(entities, **kwargs).get_result()
  File "/home/rye/local/share/google_appengine/google/appengine/api/datastore.py", line 556, in PutAsync
    return _GetConnection().async_put(config, entities, local_extra_hook)
  File "/home/rye/local/share/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1542, in async_put
    pbs = [self.__adapter.entity_to_pb(entity) for entity in entities]
  File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 562, in entity_to_pb
    pb = ent._to_pb()
AttributeError: 'Entity' object has no attribute '_to_pb'




Guido van Rossum

unread,
Jan 16, 2013, 1:16:06 PM1/16/13
to google-a...@googlegroups.com
On Wed, Jan 16, 2013 at 4:48 AM, wwwtyro <ryete...@gmail.com> wrote:
I'm not sure what I am doing wrong here; my code is almost identical to the documentation example.

My code: 

    filename = files.blobstore.create(mime_type='application/octet-stream')
   
with files.open(filename, 'a') as f:
        f
.write(json.dumps(oldblocks, separators=(',', ':')))
    files
.finalize(filename)


That can't be your *only* code, there is something else in the stack trace:

  File "/home/rye/Dropbox/projects/web/voxwright/voxwright.py", line 202, in put
    result = saveProject(data['id'], data['blocks'])

I can't tell whether that's relevant or not though. However, ISTM that somehow there is confusion between NDB models and 'Entity' instances which are what the blobstore code in the files API seems to be using. I thin you'd be best off putting "import pdb; pdb.set_trace()" in your code just before the finalize() call, and then try to figure out where things go wrong...
 




--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/EIhPvR7Q2IUJ.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.



--
--Guido van Rossum (python.org/~guido)

wwwtyro

unread,
Jan 16, 2013, 1:33:02 PM1/16/13
to google-a...@googlegroups.com, gu...@python.org
Wow, the BDFL! :O

You're right, it's not all the relevant code. After some more research, it appears to be a problem with using the blobstore in an ndb.transactional decorator. I don't know if it is relevant to the db module as well. This issue was brought to my attention: http://code.google.com/p/googleappengine/issues/detail?id=8354. It strikes me as likely to be the same problem.

I've since taken my blobstore code out of the transaction (as it probably should have been to begin with), so this issue no longer applies to me. I suspect that wrapping the code I gave in a transaction will cause the same error. Unfortunately, I pruned my buggy transactional branch and don't have the code snippet to post for you.

Thanks for responding!
Reply all
Reply to author
Forward
0 new messages