-
Notifications
You must be signed in to change notification settings - Fork 41
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
[FIX] beesdoo_shift_swap: Prevent a skip of subsequent items #534
Conversation
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.
Successful functional test on fhmunich-test: no side-effect detected
@remytms can you review? |
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.
this change seems correct to me, even though i don’t know much about the code.
/ocabot merge patch |
Hey, thanks for contributing! Proceeding to merge this for you. |
@huguesdk your merge command was aborted due to failed check(s), which you can inspect on this commit of 12.0-ocabot-merge-pr-534-by-huguesdk-bump-patch. After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red. |
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.
@carmenbianca some tests are failing but i don’t know whether it’s because of the change. would you please check this?
Modifying a list while looping over it is not allowed. It causes subsequent items to be skipped. I suspect that this is the cause of a bug where a person who wants to swap a shift is correctly unsubscribed from their old shift, but not subscribed to their new shift. But I have not been able to verify this. Signed-off-by: Carmen Bianca BAKKER <[email protected]>
9ee059d
to
a1d1d9f
Compare
@huguesdk fixed the test |
@carmenbianca while trying to understand the code, i changed it a little to make it more obvious. what do you think? |
Your proposal is not at all easy to ready for me, sorry :( I think my code is easier to read, although it does require a comment for clarity. I do like one change you made, though. I think we should rename |
with the previous code, i couldn’t understand at first why elements had to be removed from the list, and thus, why the list which is iterated over must be a copy. i think it was confusing for you too at first, which is probably why you simply removed the code removing the elements. it is only after debugging the tests that i understood that what bothers me with the previous code is the use of |
@huguesdk I gave it another go, using sets. I added a rationale to the commit message. |
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.
i’m sorry but the part of my brain that likes performance hurts when reading this, because of 2 reasons:
- the set is sorted in each iteration on the shifts instead of just once.
- the set of processed changes are removed from the set, which is correct but much less performant (in a theoretical way) than just building a new list along the way.
sets are cool to ensure elements are there only once, but to iterate over a collection in a certain order, lists are better.
i’ve searched for recommended ways of removing elements of a list while iterating over it, and the answers suggest to use a list comprehension and either create a new list, or assign the new elements to a slice of the list. i added a commit doing that. what do you think?
ef800f7
to
eafb62d
Compare
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.
@huguesdk I like this proposal. One comment. Good to merge also if you disagree with my comment.
changes -= processed | ||
# process the remaining changes and update the list to contain | ||
# only the changes that have not be processed yet. | ||
changes[:] = ( |
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.
It is not clear to me if [:]
is needed. Can't you do a list comprehension instead of a generator? i.e. replace (rec for rec in ...)
with [rec for rec in ...]
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.
you’re right. this makes sense only if the list is really big and making a copy of it should be avoided. i’ve changed it.
eafb62d
to
4a08b6e
Compare
/ocabot merge patch |
Hey, thanks for contributing! Proceeding to merge this for you. |
Congratulations, your PR was merged at c894f16. Thanks a lot for contributing to beescoop. ❤️ |
Description
Modifying a list while looping over it is not allowed. It causes subsequent items to be skipped.
I suspect that this is the cause of a bug where a person who wants to swap a shift is correctly unsubscribed from their old shift, but not subscribed to their new shift. But I have not been able to verify this.
It is not clear to me why this code exists.
Odoo task (if applicable)
T12851
Checklist before approval