Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete document with delete signal throw maximum recursion depth exceeded for 0.8.1 #350

Closed
tbicr opened this issue May 30, 2013 · 4 comments
Milestone

Comments

@tbicr
Copy link

tbicr commented May 30, 2013

If I subscribe to signals for delete event: I have RuntimeError: maximum recursion depth exceeded, because document delete called again and again: https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/queryset/queryset.py#L430. Affected on 0.8.1, on 0.7.10 all worked right: f182daa.

class Test(Document):
    test = StringField()

def do_nothing(*args, **kwargs):
    pass

post_delete.connect(do_nothing)

Test(test='001').save().delete()

Log example:

  ...
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/document.py", line 347, in delete
    self._qs.filter(**self._object_key).delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 430, in delete
    doc.delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/document.py", line 347, in delete
    self._qs.filter(**self._object_key).delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 430, in delete
    doc.delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/document.py", line 347, in delete
    self._qs.filter(**self._object_key).delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 430, in delete
    doc.delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/document.py", line 347, in delete
    self._qs.filter(**self._object_key).delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 430, in delete
    doc.delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/document.py", line 347, in delete
    self._qs.filter(**self._object_key).delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 430, in delete
    doc.delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/document.py", line 347, in delete
    self._qs.filter(**self._object_key).delete(write_concern=write_concern)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 429, in delete
    for doc in queryset:
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 157, in _iter_results
    self._populate_cache()
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 167, in _populate_cache
    self._result_cache.append(self.next())
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 1148, in next
    raw_doc = self._cursor.next()
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/pymongo/cursor.py", line 814, in next
    if len(self.__data) or self._refresh():
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/pymongo/cursor.py", line 763, in _refresh
    self.__uuid_subtype))
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/pymongo/cursor.py", line 700, in __send_message
    **kwargs)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 1006, in _send_message_with_response
    self.__pool.maybe_return_socket(sock_info)
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/pymongo/pool.py", line 358, in maybe_return_socket
    if sock_info != self._get_request_state():
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/pymongo/pool.py", line 84, in __ne__
    return not self == other
  File "/home/tbicr/Projects/cspw-ui.env/local/lib/python2.7/site-packages/pymongo/pool.py", line 78, in __eq__
    def __eq__(self, other):
  File "/home/tbicr/Soft/pycharm-129.103/helpers/pydev/pydevd.py", line 998, in trace_dispatch
    traceback.print_exc()
  File "/usr/lib/python2.7/traceback.py", line 232, in print_exc
    print_exception(etype, value, tb, limit, file)
  File "/usr/lib/python2.7/traceback.py", line 125, in print_exception
    print_tb(tb, limit, file)
  File "/usr/lib/python2.7/traceback.py", line 67, in print_tb
    '  File "%s", line %d, in %s' % (filename, lineno, name))
RuntimeError: maximum recursion depth exceeded
@rozza
Copy link
Contributor

rozza commented Jun 3, 2013

@tbicr thanks for the ticket will fix in 0.8.2

@rozza
Copy link
Contributor

rozza commented Jun 4, 2013

Your signal is incorrect you should declare a sender alternatively it will be called whenever any post_delete signal is called eg:

post_delete.connect(do_nothing, sender=Test)

I have added a lock in the background as we shouldn't infinite loop if sender isn't given

@rozza rozza closed this as completed Jun 4, 2013
@tbicr
Copy link
Author

tbicr commented Jun 4, 2013

Can you clarify next point: as I understand if I have signals and delete documents from queryset then at first I delete documents from document: https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/queryset/queryset.py#L439 (which will call queryset delete) and after with queryset: https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/queryset/queryset.py#L471? So if my conclusion right this code will call delete two times in this case for one document, probably better just send signals before and after remove?

@rozza
Copy link
Contributor

rozza commented Jun 4, 2013

It is convoluted, call_document_delete will be false so it stops signals being called twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants