Attempting to use a partial() instance as an event listener causes infinite recursion

Issue #2905 resolved
Alex Grönholm created an issue

I had this line in my app fail due to infinite recursion:

event.listen(session, 'after_commit', partial(self.publish_events, models=tuple(models_changed)))

This is a regression from 0.8.4. I haven't tested with 0.9.0b1.

The simplest way to reproduce this is:

>>> from functools import partial
>>> from sqlalchemy.util import get_callable_argspec
>>> p = partial(print, 'b')
>>> get_callable_argspec(p)
....
  File "/home/alex/virtualenv/triancore/lib/python3.3/site-packages/sqlalchemy/util/langhelpers.py", line 272,
in get_callable_argspec
    return get_callable_argspec(fn.__call__)
  File "/home/alex/virtualenv/triancore/lib/python3.3/site-packages/sqlalchemy/util/langhelpers.py", line 264,
in get_callable_argspec
    if isinstance(fn, types.FunctionType):
RuntimeError: maximum recursion depth exceeded while calling a Python object

Comments (3)

  1. Alex Grönholm reporter

    An even greater mystery is why I didn't pass the arguments as kwargs to listen() itself in the first place.

    EDIT: right, because kwargs don't work that way with listen(). Partial is the way to go.

  2. Log in to comment