()
| 833 | |
| 834 | |
| 835 | def _install_stack_protection(): |
| 836 | # Patches BaseTask.__call__ in the worker to handle the edge case |
| 837 | # where people override it and also call super. |
| 838 | # |
| 839 | # - The worker optimizes away BaseTask.__call__ and instead |
| 840 | # calls task.run directly. |
| 841 | # - so with the addition of current_task and the request stack |
| 842 | # BaseTask.__call__ now pushes to those stacks so that |
| 843 | # they work when tasks are called directly. |
| 844 | # |
| 845 | # The worker only optimizes away __call__ in the case |
| 846 | # where it hasn't been overridden, so the request/task stack |
| 847 | # will blow if a custom task class defines __call__ and also |
| 848 | # calls super(). |
| 849 | if not getattr(BaseTask, '_stackprotected', False): |
| 850 | _patched['BaseTask.__call__'] = orig = BaseTask.__call__ |
| 851 | |
| 852 | def __protected_call__(self, *args, **kwargs): |
| 853 | stack = self.request_stack |
| 854 | req = stack.top |
| 855 | if req and not req._protected and \ |
| 856 | len(stack) == 1 and not req.called_directly: |
| 857 | req._protected = 1 |
| 858 | return self.run(*args, **kwargs) |
| 859 | return orig(self, *args, **kwargs) |
| 860 | BaseTask.__call__ = __protected_call__ |
| 861 | BaseTask._stackprotected = True |
no outgoing calls
no test coverage detected