Attempting to use a partial() instance as an event listener causes infinite recursion
Issue #2905
resolved
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)
-
reporter -
repo owner OK, not much we can do with that besides skip the check, but the check there isn't critical in the majority of cases. it's explained in the changelog. c450cd6cb6d0c8fed110abc
-
repo owner - changed milestone to 1.0.xx
- Log in to comment
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.