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

OptionList safe duplicate check #3459

Merged
merged 12 commits into from
Oct 5, 2023

Conversation

davep
Copy link
Contributor

@davep davep commented Oct 4, 2023

Simply put: the duplicate check inside OptionList was happening after a new option was added to the internal structures. This was almost fine back when there was only a method for adding a single option, and even then it was only fine if a DuplicateID exception was treated as a "just give up using this OptionList signal". Or put another way: attempting to add a duplicate ID had unintended side-effects, making every subsequent attempt to add an option appear to be the creation of a duplicate.

This PR moves to a preflight check for duplicate IDs.

Fixes #3455.

davep added 3 commits October 4, 2023 20:24
Simply put: until now the OptionList was adding the new options and then
checking if the ID was a duplicate. If some code was to then catch
DuplicateID and treat it as a pass this would then have an unintended
side-effect that the duplicate had been added anyway. The ultimate effect of
this being that once there was an attempt to add a duplicate, nothing more
could be added to that OptionList.

Fixes Textualize#3455.
@davep davep added bug Something isn't working Task labels Oct 4, 2023
@davep davep self-assigned this Oct 4, 2023
@davep davep marked this pull request as ready for review October 4, 2023 20:42
This way there's less chance of a duplicate report of a duplicate.
src/textual/widgets/_option_list.py Outdated Show resolved Hide resolved
src/textual/widgets/_option_list.py Outdated Show resolved Hide resolved
davep and others added 4 commits October 5, 2023 10:42
In conversation we've decided that it's not that necessary to list all of
the IDs that are duplicates; with this in mind we can whittle down the work
being done to look for duplicates.

Co-authored-by: Will McGugan <[email protected]>
Because apparently I can't type English.
Likely doesn't make a whole heap of difference, but the {} vs the [] was a
typo and really conceptually it is a list of new options with IDs.
Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

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

Just a recomendation.

src/textual/widgets/_option_list.py Outdated Show resolved Hide resolved
@davep davep merged commit cc04d30 into Textualize:main Oct 5, 2023
22 checks passed
@davep davep deleted the option-list-safe-duplicate-check branch October 5, 2023 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OptionList duplicate ID detection not working as expected
3 participants