Skip to content

fix: Now getRelatedContactRelationships handle null arg#2982

Merged
JF-Cozy merged 1 commit intomasterfrom
feat/contact
Apr 2, 2026
Merged

fix: Now getRelatedContactRelationships handle null arg#2982
JF-Cozy merged 1 commit intomasterfrom
feat/contact

Conversation

@JF-Cozy
Copy link
Copy Markdown
Contributor

@JF-Cozy JF-Cozy commented Apr 2, 2026

As we can remove fields now, relatedContact can be empty

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue in contact relationship management where the system would fail when processing contacts with missing or undefined related contact information. Contact operations now handle these edge cases gracefully.

As we can remove fields now, relatedContact can be empty
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Walkthrough

The getRelatedContactRelationships function in the helpers file has been updated to add an input validation guard. This guard checks if the relatedContact parameter is falsy or undefined and immediately returns an empty object in those cases. Previously, the function would proceed to call relatedContact.filter(...), which would fail when relatedContact is null or undefined. The rest of the function logic remains unchanged. Two lines have been added to implement this guard.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding null argument handling to getRelatedContactRelationships, which matches the code modification of guarding against falsy/undefined relatedContact inputs.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/contact

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/helpers.js`:
- Around line 213-214: The helper early-return currently returns an empty object
when relatedContact is falsy, which omits the related key and lets
oldContactCleaned?.relationships.related persist; update the early-return in the
helper (the branch that checks relatedContact) to return an object that
explicitly clears relationships.related (e.g., return { related: [] }) so
formValuesToContact correctly replaces prior related entries when calling
formValuesToContact/merging with oldContactCleaned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 06d3c373-40bb-4574-ba49-97a520776a97

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac8873 and fa2aa84.

📒 Files selected for processing (1)
  • packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/helpers.js

Comment on lines +213 to +214
if (!relatedContact) return {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Returning {} here can keep stale relationships.related

On Line 213, returning {} when relatedContact is null/falsy means no related key is produced. In formValuesToContact (packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/formValuesToContact.js:38-52), that allows previously merged oldContactCleaned?.relationships.related to survive instead of being cleared.

Suggested fix
 export const getRelatedContactRelationships = relatedContact => {
-  if (!relatedContact) return {}
+  if (!relatedContact) return { related: { data: [] } }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!relatedContact) return {}
export const getRelatedContactRelationships = relatedContact => {
if (!relatedContact) return { related: { data: [] } }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/helpers.js` around
lines 213 - 214, The helper early-return currently returns an empty object when
relatedContact is falsy, which omits the related key and lets
oldContactCleaned?.relationships.related persist; update the early-return in the
helper (the branch that checks relatedContact) to return an object that
explicitly clears relationships.related (e.g., return { related: [] }) so
formValuesToContact correctly replaces prior related entries when calling
formValuesToContact/merging with oldContactCleaned.

@JF-Cozy JF-Cozy merged commit d3677ba into master Apr 2, 2026
3 checks passed
@JF-Cozy JF-Cozy deleted the feat/contact branch April 2, 2026 12:29
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.

2 participants