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

Fix for bug in Plan duplication results in original plan identifier b… #3441

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

johnpinto1
Copy link
Contributor

…eing copied.

Change in class method Plan.deep_copy:

  • Firstly, on duplicating the Plan we set the plan identifier to nil and save.
  • Then we fill the identifier variable with the Plan id that was regenerated when the duplicate copy was save in the previous.
  • We then persist this change by saving the Plan again.

@johnpinto1 johnpinto1 self-assigned this Jul 29, 2024
@johnpinto1 johnpinto1 force-pushed the plan-deep-copy-bug-copies-old-id-as-identifier branch from de27ebf to 574f3bc Compare July 29, 2024 11:41
…eing copied.

Change in class method Plan.deep_copy:
  - Firstly, on duplicating the Plan we set the plan identifier to nil and save.
  - Then we fill the identifier variable with the Plan id that was
      regenerated when the duplicate copy was save in the previous.
  - We then persist this change by saving the Plan again.
@johnpinto1 johnpinto1 force-pushed the plan-deep-copy-bug-copies-old-id-as-identifier branch from 574f3bc to 36e5b7d Compare July 29, 2024 11:42
plan_copy.save!
# Copy newly generated Id to the identifier
plan_copy.identifier = plan_copy.id
plan.save!
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. I tested the PR and it all appears to be behaving as it should. :) I just have a couple of thoughts as well.

The last two lines are having the final say in the saved value of plan_copy.identifier. So assigning plan_copy.identifier = nil prior to the first save doesn't seem necessary.

Also, plan_copy.identifier is a String, but plan_copy.id is an integer. I guess we have similar code in https://github.com/DMPRoadmap/roadmap/blob/main/app/controllers/plans_controller.rb#L140 (@plan.identifier = @plan.id.to_s). However, I guess Rails is automatically typecasting the value to a String here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @aaronskiba. I have made the changes suggested in a separate commit.

…eing copied.

Changes (suggested by @aaronskiba):
  - removed an unnecessary line
      plan_copy.identifier = nil
  - cast to string the integer-valued plan id
    plan_copy.identifier = plan_copy.id.to_s
Copy link
Contributor

@aaronskiba aaronskiba left a comment

Choose a reason for hiding this comment

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

Looks good. 👍

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.

3 participants