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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Fixed
- Fixed a bug in the deep copy of plans where the old identifier was being copied into the new plan. We now copy the generated id of the new plan to the identifier field.

## v4.2.0

**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.**
Expand Down
3 changes: 3 additions & 0 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ def self.deep_copy(plan)
plan_copy.title = "Copy of #{plan.title}"
plan_copy.feedback_requested = false
plan_copy.save!
# Copy newly generated Id to the identifier
plan_copy.identifier = plan_copy.id.to_s
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.

plan.answers.each do |answer|
answer_copy = Answer.deep_copy(answer)
answer_copy.plan_id = plan_copy.id
Expand Down
Loading