Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dispatcher use one context per update #1283

Merged
merged 4 commits into from
Feb 13, 2019
Merged

Conversation

Eldinnie
Copy link
Member

@Eldinnie Eldinnie commented Nov 1, 2018

It gives user the option to overload context with their own properties in a lower group handler if they like

It gives user the option to `overload` context with their own properties in a lower group handler if they like
Copy link
Member

@jsmnbom jsmnbom left a comment

Choose a reason for hiding this comment

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

This looks good to me. A bit cluttered with the flake8 stuff (would've been nice to merge that to master first, so our builds there don't fail all the time, but mweh)

  1. We should document this behaviour somewhere.
  2. Should context maybe be reset after each handler? Like resetting only the standard attributes. It just feels a bit strange to me that (using test_one_context_per_update as example) I would be able to access context.matches in two, even though it does not have a regex filter (and therefore no matches).
  3. This is all still threadsafe right?

@Eldinnie
Copy link
Member Author

Eldinnie commented Nov 1, 2018

  1. Yes in the wiki I guess?
  2. I think that's overthingking it personally...
  3. ehm.... I guess it might not be on run_async handlers....

@jsmnbom
Copy link
Member

jsmnbom commented Nov 1, 2018

  1. maybe in the ContextCallback class too? Like "You can add attributes to this class and they will propagate to handlers in higher dispatcher groups."
  2. Alright, I do think we should add another note to somehow describe this behaviour
  3. We need to test that somehow I think

@jsmnbom
Copy link
Member

jsmnbom commented Nov 8, 2018

Okay, so this feature simply doesn't work with @run_async at all... Is that okay?

Test code to show not working/working (uncomment/comment the @run_async

# @run_async
def a(u, c: CallbackContext):
    print(c)
    c.q = 1

# @run_async
def b(u, c: CallbackContext):
    print(c)

u = Updater(token, use_context=True)
d = u.dispatcher
d.add_handler(MessageHandler(Filters.all, b))
d.add_handler(MessageHandler(Filters.all, a), -1)

u.update_queue.put(Update(0, message=Message(0, None, None, None)))

u.start_polling()
u.idle()

@jsmnbom jsmnbom added this to the V12 milestone Feb 8, 2019
- Add note about how you can add custom attributes to context.
- Add warnings about how run_async and custom attributes should not be used together.
@jsmnbom jsmnbom merged commit b02b688 into V12 Feb 13, 2019
@Eldinnie Eldinnie deleted the one-context-per-update branch February 14, 2019 12:49
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants