Pass job to error handler where possible #2570
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #2568 - at least partly.
For jobs that run only once, APS already drops the job from memory before reporting any exception so that we can't get it back by its ID. One could maybe try to work around that somehow by reworking some of the internals of
JobQueue
(bascially tell APS to runjob.run(dispatcher)
instead of running thecallback
directly, but I'm not sure if that's worth it.That would also make it even more complicated for custom persistence solutions like the recently introduced
ptbcontrib/ptb_sqlalchemy_jobstore
(even though this shouldn't be the main reason to to do it)The main use case probably is to stop repeating jobs that cause exceptions, anyway.
Because this adds a new parameter to
CallbackContext.from_error
, this is maybe kind of breaking if people subclassed forContextTypes
and overrode that. Anyway, not that urgent so I'll be putting it on the v14 milestone for now.edit: We could just make
tg.ext.Job
callable (wherejob(dispatcher)
just doesjob.run(dispatcher)
). This would probably solve all of the issues mentioned above 🤔Checklist for PRs
.. versionadded:: version
,.. versionchanged:: version
or.. deprecated:: version
to the docstrings - did that but should be updated before merging