Decorating a event function may cause unexpected errors
mlubimow opened this issue · 0 comments
mlubimow commented
Context
It's not technically a bug, but current behaviour of a mechanism to run a scheduled function just doesn't seem to be correct. Adding a very subtle, safe looking change can cause scheduled events to fail.
Expected Behavior
Event functions should be required to accept kwargs
Actual Behavior
Params passed to functions are different depending if it has varargs or not
Possible Fix
Make "function" in events deprecated, replace it with "handler" or some other key and add checks to ensure that function is correct.
Steps to Reproduce
- Create a event function:
def some_task():
# do something
return True
- Add it to events in zappa_settings.json
"events": [
{
"function": "my_tasks.some_task",
"expression": "cron(0 1 * * ? *)"
}
]
- One day someone adds a generic decorator:
def generic_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
# do something
return func(*args, **kwargs)
return wrapper
@generic_decorator
def some_task():
# do something
return True
- Task fails at night. event and context variables get passed to some_task, but it doesn't accept any arguments. Works like a charm in unit tests.
Your Environment
n/a