Skip to content

fix(tasks): use document .save() instead of new Model() in repository update#3440

Merged
PierreBrisorgueil merged 2 commits intomasterfrom
fix/repository-update-duplicate-creation-3433
Apr 9, 2026
Merged

fix(tasks): use document .save() instead of new Model() in repository update#3440
PierreBrisorgueil merged 2 commits intomasterfrom
fix/repository-update-duplicate-creation-3433

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Contributor

@PierreBrisorgueil PierreBrisorgueil commented Apr 9, 2026

Summary

  • Replace new Task(task).save() with task.save() in tasks.repository.js update function to prevent duplicate document creation when the mongoose document's _id is not recognized or isNew is still set
  • Aligns the tasks repository with the safe pattern already used by organizations and memberships repositories

Test plan

  • Existing integration test should be able to create, update, and delete his own task passes
  • All 756 tests pass, 64 suites
  • Lint clean
  • Coverage thresholds maintained

Closes #3433

Summary by CodeRabbit

  • Refactor
    • Improved efficiency of task update operations through optimized data handling.

… update

Prevents duplicate document creation when the update function receives a
mongoose document without a recognized _id or with isNew still set.
Aligns tasks repository with the pattern already used by organizations
and memberships repositories.

Closes #3433
Copilot AI review requested due to automatic review settings April 9, 2026 05:40
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 27 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 15 minutes and 27 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4827596e-74dd-4d69-afbb-11c5a75380a0

📥 Commits

Reviewing files that changed from the base of the PR and between 2439254 and f9d44db.

📒 Files selected for processing (1)
  • modules/tasks/repositories/tasks.repository.js

Walkthrough

Updated the repository update operation to persist the provided Mongoose document instance via task.save() instead of re-instantiating it with new Task(task).save(). The operation continues to return a populated task document through the same populate chain.

Changes

Cohort / File(s) Summary
Repository Update Pattern
modules/tasks/repositories/tasks.repository.js
Modified update() method to use existing Mongoose document instance (task.save()) instead of creating a new Task model instance (new Task(task).save()). Addresses duplicate creation risk when _id is absent or isNew flag is set.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description covers the main change, rationale, and test plan, but lacks explicit coverage of the required template sections like Risk level, Cross-module impact, Validation checklist items, and Guardrails checks. Add explicit Risk level assessment, Cross-module impact statement, and complete the Validation and Guardrails checklists to fully align with the template structure.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: replacing new Model() constructor pattern with direct document .save() in the repository update function.
Linked Issues check ✅ Passed The pull request directly addresses the primary objective of issue #3433 by replacing the risky new Model().save() pattern with safer document.save() in the tasks repository.
Out of Scope Changes check ✅ Passed The code change is narrowly scoped to the tasks repository update function with no unrelated modifications, fully aligning with the single issue objective #3433.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/repository-update-duplicate-creation-3433

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the tasks repository update behavior to persist changes via the existing Mongoose document instance, preventing accidental duplicate task creation during updates and aligning with the safer repository pattern used elsewhere.

Changes:

  • Replace new Task(task).save() with task.save() in TasksRepository.update().
  • Continue to populate default relations after persistence.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.51%. Comparing base (b4e2da9) to head (f9d44db).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3440   +/-   ##
=======================================
  Coverage   85.51%   85.51%           
=======================================
  Files         113      113           
  Lines        2879     2879           
  Branches      795      795           
=======================================
  Hits         2462     2462           
  Misses        331      331           
  Partials       86       86           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil PierreBrisorgueil merged commit 5fc9ba4 into master Apr 9, 2026
5 checks passed
@PierreBrisorgueil PierreBrisorgueil deleted the fix/repository-update-duplicate-creation-3433 branch April 9, 2026 06:39
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.

Repository update pattern uses new Model().save() — risks duplicate creation

2 participants