()
| 858 | |
| 859 | |
| 860 | def _install_stack_protection(): |
| 861 | # Patches BaseTask.__call__ in the worker to handle the edge case |
| 862 | # where people override it and also call super. |
| 863 | # |
| 864 | # - The worker optimizes away BaseTask.__call__ and instead |
| 865 | # calls task.run directly. |
| 866 | # - so with the addition of current_task and the request stack |
| 867 | # BaseTask.__call__ now pushes to those stacks so that |
| 868 | # they work when tasks are called directly. |
| 869 | # |
| 870 | # The worker only optimizes away __call__ in the case |
| 871 | # where it hasn't been overridden, so the request/task stack |
| 872 | # will blow if a custom task class defines __call__ and also |
| 873 | # calls super(). |
| 874 | if not getattr(BaseTask, '_stackprotected', False): |
| 875 | _patched['BaseTask.__call__'] = orig = BaseTask.__call__ |
| 876 | |
| 877 | def __protected_call__(self, *args, **kwargs): |
| 878 | stack = self.request_stack |
| 879 | req = stack.top |
| 880 | if req and not req._protected and \ |
| 881 | len(stack) == 1 and not req.called_directly: |
| 882 | req._protected = 1 |
| 883 | return self.run(*args, **kwargs) |
| 884 | return orig(self, *args, **kwargs) |
| 885 | BaseTask.__call__ = __protected_call__ |
| 886 | BaseTask._stackprotected = True |
no outgoing calls
no test coverage detected