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

Conversation

@Eldinnie
Copy link
Member

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
@Eldinnie Eldinnie force-pushed the one-context-per-update branch from 2f13c82 to f3f9e8d Nov 1, 2018
Copy link
Member

jsmnbom left a comment

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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
jsmnbom added 3 commits 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 Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.