Skip to content

feat: Return handler upon decorator invocation#934

Merged
janbuchar merged 4 commits into
apify:masterfrom
mylank:feat/multi-labelled-handler
Jan 27, 2025
Merged

feat: Return handler upon decorator invocation#934
janbuchar merged 4 commits into
apify:masterfrom
mylank:feat/multi-labelled-handler

Conversation

@mylank

@mylank mylank commented Jan 24, 2025

Copy link
Copy Markdown
Contributor

Description

Currently, wrapping a handler with a decorator nullifies the function because it returns None in the code. See the "None" popup over here:
image

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

  • Added a test to ensure handler is not nullified
  • Added a test for multiple labels assigned to a single handler

Checklist

  • CI passed

Please let me know your thoughts! 🙌

@janbuchar janbuchar self-requested a review January 27, 2025 14:03

@janbuchar janbuchar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @mylank! Would you mind sharing the use case for this? Is it just routing multiple labels to the same handler, or something more sophisticated?

@janbuchar janbuchar merged commit 9ec0aae into apify:master Jan 27, 2025
@vdusek vdusek added this to the 107th sprint - Tooling team milestone Jan 27, 2025
@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. enhancement New feature or request. labels Jan 27, 2025
@mylank

mylank commented Jan 29, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for your contribution @mylank! Would you mind sharing the use case for this? Is it just routing multiple labels to the same handler, or something more sophisticated?

Thanks for the quick response! 🙌 Of course; so I have two pages that are almost identical but one requires just a couple of actions more. I tried a couple of different options but in the end I just thought the cleanest would be to tag the same handler with 2 labels and just use an if statement like in the docs.

So yes, my specific use case is indeed just for routing multiple labels to the same handler that require only a small deviation from the general logic!

Thanks for merging this in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants