Organizational Research By

Surprising Reserch Topic

operationfailure database error when threading in mongoengine pymongo

operationfailure database error when threading in mongoengine pymongo  using -'django,mongodb,celery,pymongo,mongoengine'

I have a function that will read data from a website, process it, and then load it into MongoDB. When I run this without threading it works fine but as soon as I set up celery tasks that just call this one function I frequently get the following error: "OperationFailure: database error: unauthorized db:dbname lock type:-1"

It's somewhat odd because if I run the non-celery version on multiple terminals, I do not get this error at all.

I suspect it has something to do with there not being an open connection to Mongo although in my code I'm opening one up right before every Mongo call.

The exact exception is below:

Task twitter[a974bfcc-d6ca-4baf-b36f-cae9143ce2d9] raised exception: OperationFailure(u'database error: unauthorized db:data lock type:-1 client:',)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/celery/execute/", line 36, in trace
  return cls(states.SUCCESS, retval=fun(*args, **kwargs))
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/celery/app/task/", line 232, in __call__
  return*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/celery/app/", line 172, in run
  return fun(*args, **kwargs)
File "/djangoblog/network/", line 40, in twitter
File "/djangoblog/network/", line 255, in GetTweetsTwitter
  id = SaveTweet(user, network, tweet)
File "/djangoblog/network/", line 150, in SaveTweet
  if mmo.Moment.objects(,source_id=id, == 0:
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mongoengine/", line 933, in count
  return self._cursor.count(with_limit_and_skip=True)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mongoengine/", line 563, in _cursor
  self._cursor_obj = self._collection.find(self._query,
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mongoengine/", line 493, in _collection
  if not in db.collection_names():
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pymongo/", line 361, in collection_names
  names = [r["name"] for r in results]
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pymongo/", line 703, in next
  if len(self.__data) or self._refresh():
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pymongo/", line 666, in _refresh
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pymongo/", line 628, in __send_message self.__tz_aware)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pymongo/", line 101, in _unpack_response error_object["$err"])
OperationFailure: database error: unauthorized db:data lock type:-1 client:

Sorry for the formatting but if you look at the line that starts with mmo.Moment there's a connection being opened right before that's called.

Doing a bit of research it looks as if it has something to do with the way threading is handled in PyMongo - - I may need to start closing the connections but I'd expect MongoEngine to be doing this..

asked Sep 29, 2015 by rajeevr642
0 votes

Related Hot Questions

1 Answer

0 votes
answered Sep 29, 2015 by nimisha.jagtap