Commit 9ec0aae
authored
feat: Return request handlers from decorator methods to allow further decoration (#934)
### Description
Currently, wrapping a handler with a decorator nullifies the function
because it returns `None` [in the
code](https://github.com/apify/crawlee-python/blob/28579996e454e19dd69ed6ee09e4293d4e056a6e/src/crawlee/router.py#L44-L45).
See the "None" popup over here:

By having the router.handler function return the original input handler,
we can now reuse the handler function again in other places as it's not
set to `None` anymore. This allows for invoking the original function
even after applying the decorator and for adding multiple decorators to
the same handler function. The latter for example allows for using the
same handler function for multiple labels (a use case I ran into).
### Issues
Not applicable.
### Testing
- [x] Added a test to ensure handler is not nullified
- [x] Added a test for multiple labels assigned to a single handler
### Checklist
- [x] CI passed
Please let me know your thoughts! 🙌1 parent 2fdfd87 commit 9ec0aae
2 files changed
Lines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
45 | 47 | | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
0 commit comments