Skip to content

[BUG] Change condition in Filters.user to avoid error with empty lists #1562

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

Closed
xates opened this issue Oct 17, 2019 · 5 comments · Fixed by #1757
Closed

[BUG] Change condition in Filters.user to avoid error with empty lists #1562

xates opened this issue Oct 17, 2019 · 5 comments · Fixed by #1757

Comments

@xates
Copy link
Contributor

xates commented Oct 17, 2019

Consider changing this condition

if not (bool(user_id) ^ bool(username)):

to something like

if (user_id is None) == (username is None):

To avoid throwing the ValueError "One and only one of user_id or username must be used" when an empty list of user_ids or usernames is issued.

Similarly for Filters.chat.

PS This should also be 3 to 4 times faster.

@xates
Copy link
Contributor Author

xates commented Oct 17, 2019

(I can make a PR if you wish)

Copy link
Member

tsnoam commented Oct 17, 2019

@xates Hi,

Please help us to understand what is the problem. As we understand it:

  1. One and only one of user_id or username must be used
  2. Neither user_id nor username are legitimate as empty lists.

What is the usecase which you were trying to use?

@xates
Copy link
Contributor Author

xates commented Oct 17, 2019

Please help us to understand what is the problem. As we understand it:

  1. One and only one of user_id or username must be used
  2. Neither user_id nor username are legitimate as empty lists.

The problem is that currently if an empty list of either user ids or usernames is used, it is still considered by the cited precondition as if no parameter was set, because bool([]) = False, where instead it is actually set.

What is the usecase which you were trying to use?

A function of the bot that is restricted (or prohibited) to a certain group of users which may be empty at the first start of the bot or generally up to a certain moment.

Copy link
Member

tsnoam commented Oct 17, 2019

@xates Thanks for clarifying.
This was not a use case we initially thought of, however it is a very reasonable one.
While fixing this bug we should take into account thread safety.

Also, if you'd like to write the fix, we'll be happy to see the PR.
Just write down how you intend to tackle thread safety prior to implementation. So we'll be in sync about that.

@xates
Copy link
Contributor Author

xates commented Oct 17, 2019

I didn't think about thread safety, honestly. The solution I had thought of is the one in the opening post.
I can't imagine in which situation a problem could arise, though.
I am not very shrill on the subject either.

@jh0ker jh0ker changed the title Change condition in Filters.user to avoid error with empty lists [BUG] Change condition in Filters.user to avoid error with empty lists Oct 25, 2019
@Poolitzer Poolitzer added this to the 12.3 milestone Nov 11, 2019
@tsnoam tsnoam modified the milestones: 12.3, 12.5 Nov 15, 2019
@Bibo-Joshi Bibo-Joshi removed this from the 12.5 milestone Feb 6, 2020
@Bibo-Joshi Bibo-Joshi mentioned this issue Feb 21, 2020
8 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 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 a pull request may close this issue.

5 participants