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

fixes #1278 #1365

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

blsouthcott
Copy link

@blsouthcott blsouthcott commented Jun 20, 2023

Proposed Changes

  • Added a test for the copy nutrition plan function/endpoint
  • Refactored copy nutrition plan function to avoid potential race condition that occurs, causing meals and meal items not to be copied when creating a copy of the nutrition plan

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

  • Tests for the changes have been added (for bug fixes / features)
  • Added yourself to AUTHORS.rst

Other questions

  • Do users need to run some commmands in their local instances due to this PR
    (e.g. database migration)? No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant