-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Check for update.effective_chat explicitly in ConversationHandler.check_update #959
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
Merged
tsnoam
merged 2 commits into
python-telegram-bot:master
from
nmlorg:conversationhandler-check_update
Feb 12, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I'm confused form the logic here (it doesn't necessarily make it wrong though) so I have some questions:
and (update.inline_query or update.chosen_inline_result)
removed intentionally or is it by mistake? If intentionally please explain why.and
,and not
&or
conditionals it makes it hard to read (even if its correct). Can you be so kind and add parentheses to make the logic easier to read?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, this piece of code was barely readable before (at least to me) so this change made it much more difficult to undestand...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code was:
and I first changed it to group related conditions by line:
i.e. each line contains conditions that are joined by
and
, and the lines are separated byor
. Due to order of operations rules, this means each line is now the same as if it had been enclosed in parentheses:The actual logic change (the second commit) was to remove the
(update.inline_query or update.chosen_inline_result)
check and replace it with a check fornot update.effective_chat
. It seemed pretty clear the intent was to exclude updates that don't have achat
assigned, which includes inline_query and chosen_inline_result (as explicitly tested in the original logic) as well as callback_query from inline messages, shipping_query, and pre_checkout_query (as documented in Update.effective_chat). So I could have changed the logic to exclude those additional types explicitly, but ultimately the update gets passed into _get_key which blindly dereferences update.effective_chat, so either that would need to be modified to beif self.per_chat and chat is not None:
(like the per_user check) or go ahead and just check for effective_chat before calling _get_key, which is what I did.The one remaining issue is that last line, which excludes callback_query updates that don't have a message attached when per_chat is set, which doesn't seem to make sense to me. The only time update.callback_query.message is dereferenced is again in _get_key when per_message is set and update.callback_query.inline_message_id is not set, neither of which seem related to what's being tested. It's possible the original logic's author meant to include that logic tacked onto the previous per_message test:
i.e. if per_message and either it's not a callback_query or it is a callback_query but callback_query.message is not set (though that's not strictly necessary, and still not sure what the per_chat check in the middle is for).
(Personally, if I was confident that _get_key's logic was perfect, I would just get rid of that whole block and have _get_key return
None
or something itself if the update isn't relevant, and do:but the smallest necessary change is to explicitly check for update.effective_chat before dereferencing it, and either exclude all updates without one (like I did) or include them even if per_chat is set (
if self.per_chat and chat is not None:
).)(Do you still want me to add the extra explicit parens?)