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.
Proposed Changes
Notes:
The way the function is currently written in the master branch, the newly added test does not pass. The test does pass with the changes in this branch.
I was able to reproduce the issue locally, but only inconsistently. I was able to reliably reproduce it by creating a new account, adding a plan, and trying to copy that plan. However, I wasn’t able to consistently reproduce the issue for established accounts.
When I stepped through the code with a debugger, I didn’t encounter the issue. So I think a race condition can occur where plan_copy and meal_copy are still referencing the original plan and meal objects, even though those objects should be updated with the primary key for the new database entry. I suspect that creating new objects using the values of the fields of the original objects more reliably avoids a potential race condition because there are two completely separate objects, whereas currently plan and plan_copy, and meal and meal_copy, each reference the same object.
Please check that the PR fulfills these requirements
Other questions
(e.g. database migration)? No