Sentry-python: Enforce functools.wraps on all monkeypatches

Created on 10 Jul 2019  路  6Comments  路  Source: getsentry/sentry-python

I'm using celery-once to make sure some tasks are only run one at a time. The lock is acquired in apply_async and released in after_return.

When I use the CeleryIntegration I'm not seeing any of the locks being released after the task has finished running. I'm not very familiar with the inner workings of celery, but any ideas what's going on?

bug

All 6 comments

Do you see this bug in Raven-Python? Raven uses official Celery hooks while this SDK aggressively (for lack of a better word) monkeypatches Celery to capture exceptions happening in hooks, and to work around some bugs in Celery 3.

I think I've narrowed it down to an issue with celery-once. The library uses the task name and call arguments from the run method (using `inspect.getcallargs) to generate the lock key. It generates the key both when acquiring and releasing the lock. It seems the arguments before and after the task gets patched are slightly different (the wrapper takes in optional args).

I don't think this is strictly an issue with the SDK, so I'll close this for now, thanks for looking at it though.

@mumumumu if it's a missing functools.wraps somewhere we can fix it in the SDK as well, no big deal

Thanks @untitaker, that'd be much appreciated. Adding a @wraps(f) to the _wrap_task_call _inner function does fix the issue for me.

We should do this everywhere then. Monkeypatches are quite inconsistent across the codebase.

Since this is blocking you I'll just get a minimal fix out of the door.

Proper wrapping will likely take more effort (possibly using wrapt instead of functools).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cichy767 picture cichy767  路  6Comments

zegerius picture zegerius  路  4Comments

synic picture synic  路  5Comments

hyperknot picture hyperknot  路  4Comments

tonal picture tonal  路  4Comments