Skip to content

Revert "fix: add validation for null/undefined traits" - #4688

Merged
krishna2020 merged 1 commit into
developfrom
revert-4684-fix/sendinBlue
Sep 29, 2025
Merged

krishna2020 merged 1 commit into
developfrom
revert-4684-fix/sendinBlue

Conversation

@ItsSudip

Copy link
Copy Markdown
Member

Reverts #4684

@ItsSudip
ItsSudip requested a review from a team as a code owner September 29, 2025 11:14
@coderabbitai

coderabbitai Bot commented Sep 29, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Sendinblue integration now handles missing or undefined user attributes without errors, while continuing to map valid attributes as before.
  • Refactor

    • Minor internal iteration update with no functional impact.
  • Tests

    • Removed tests tied to the previous strict validation behavior.

Walkthrough

Removed null/undefined traits guard in Sendinblue util; refactored iteration from for-loop to Object.keys(...).forEach. Deleted corresponding tests, including those expecting an error on undefined traits and behaviors for empty/falsy values. No changes to exports.

Changes

Cohort / File(s) Summary
Sendinblue trait transform
src/v0/destinations/sendinblue/util.js
Removed traits presence validation; replaced for-loop over attribute map with Object.keys(...).forEach; kept mapping logic otherwise intact.
Sendinblue transform tests
src/v0/destinations/sendinblue/util.test.js
Deleted test suite covering trait mapping/removal, ignoring unmapped/falsy values, empty traits result, and error on undefined traits.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant U as transformUserTraits

  rect rgba(230,230,255,0.4)
  note over U: Old flow
  C->>U: traits, attributeMap
  alt traits is undefined/null
    U-->>C: throw Error("...traits is required")
  else valid object
    U->>U: iterate attributeMap keys (for-loop)
    U-->>C: mapped attributes
  end
  end

  rect rgba(230,255,230,0.4)
  note over U: New flow
  C->>U: traits, attributeMap
  U->>U: iterate Object.keys(attributeMap).forEach
  U-->>C: mapped attributes (no pre-check)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggestions:

  • Confirm behavior for undefined/null traits is desired; add explicit handling or inline docs.
  • Re-introduce tests for current expected behavior (including falsy value handling) to prevent regressions.

Possibly related PRs

Suggested reviewers

  • utsabc
  • manish339k

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description only contains a one-line statement that this PR reverts the previous PR, omitting all required template sections such as a summary of changes, the related Linear task, objectives, behavior or dependency details, technical considerations, and the developer checklist. Without these sections, reviewers lack context on why the revert is necessary, what impact it has, and whether any dependent tasks or validations were completed. Consequently, the description does not meet the repository’s standards as defined by the provided template. Please expand the PR description to include each heading from the template: a brief explainer of the code changes, the related Linear task ID, detailed objectives and rationale, any changes to behavior or dependencies, technical or performance considerations, and confirmation of the developer checklist items.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the intent to revert the previous “fix: add validation for null/undefined traits” change, directly referencing the specific commit being undone and avoiding extraneous detail. This makes it clear to reviewers and maintainers what the primary action is without including file lists or unrelated context. The phrasing follows conventional GitHub revert-title patterns and aligns with the actual modifications in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch revert-4684-fix/sendinBlue

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

@ItsSudip
ItsSudip enabled auto-merge (squash) September 29, 2025 11:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/v0/destinations/sendinblue/util.js (1)

117-130: Verify transformUserTraits callers in transform.js and restore minimal tests

Call sites in src/v0/destinations/sendinblue/transform.js at lines 101, 139 and 243 invoke transformUserTraits(payload.attributes, …) or transformUserTraits(payload.properties, …). After the recent revert:

  • Ensure transformUserTraits handles undefined/null input without throwing.
  • Preserve falsy values (0, false), filtering only null/undefined.
  • Avoid mutating the original traits object.

Re-add tests for:

  • traits = undefined/null returns {}.
  • correct mapping when values are present.
  • retention of 0/false; exclusion of only null/undefined.
  • non-mutation of the input object.

I can draft these tests or refactoring suggestions if helpful.

🧹 Nitpick comments (1)
src/v0/destinations/sendinblue/util.js (1)

100-108: Avoid mutating the input object in refineUserTraits

const refinedTraits = userTraits; keeps the same reference and delete mutates the caller’s object.

-const refineUserTraits = (userTraits, attributeMap) => {
-  const refinedTraits = userTraits;
+const refineUserTraits = (userTraits, attributeMap) => {
+  const refinedTraits = { ...userTraits };
   Object.keys(userTraits).forEach((key) => {
     if (Object.prototype.hasOwnProperty.call(attributeMap, key)) {
       delete refinedTraits[key];
     }
   });
   return refinedTraits;
 };

(If performance is a concern, copy only when attributeMap has any matching keys.)

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 840bcef and d6b0fd5.

📒 Files selected for processing (2)
  • src/v0/destinations/sendinblue/util.js (1 hunks)
  • src/v0/destinations/sendinblue/util.test.js (0 hunks)
💤 Files with no reviewable changes (1)
  • src/v0/destinations/sendinblue/util.test.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/v0/destinations/sendinblue/util.js
🧠 Learnings (1)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4589
File: scripts/common.ts:74-78
Timestamp: 2025-08-28T15:39:08.293Z
Learning: User ItsSudip prefers simpler solutions over complex edge case handling, especially when the simpler approach is sufficient for the actual use case.
🧬 Code graph analysis (1)
src/v0/destinations/sendinblue/util.js (1)
src/v0/destinations/sendinblue/transform.js (3)
  • userTraits (101-104)
  • userTraits (139-139)
  • userTraits (243-246)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)

Comment on lines +122 to +127
Object.keys(attributeMap).forEach((key) => {
const traitValue = traits[key];
if (traitValue) {
userTraits[attributeMap[key]] = traitValue;
}
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Prevent crash on undefined traits and preserve falsy (0/false) values

  • If traits is undefined/null, traits[key] will throw.
  • if (traitValue) drops legitimate values like 0 and false.

Minimal, non-opinionated fix that keeps the “no hard error” behavior after the revert:

-  const userTraits = traits;
-  Object.keys(attributeMap).forEach((key) => {
-    const traitValue = traits[key];
-    if (traitValue) {
-      userTraits[attributeMap[key]] = traitValue;
-    }
-  });
+  // start with a safe, shallow copy to avoid mutating the input
+  const userTraits = traits && typeof traits === 'object' ? { ...traits } : {};
+  Object.keys(attributeMap).forEach((key) => {
+    const traitValue = traits?.[key];
+    // only skip null/undefined; keep 0/false
+    if (traitValue !== null && traitValue !== undefined) {
+      userTraits[attributeMap[key]] = traitValue;
+    }
+  });

Notes:

  • If contactAttributeMapping can be falsy, consider const attributeMap = getHashFromArray(... ) || {}; one line above.
  • This aligns with the simpler behavior (no throw) while making the function total. Based on learnings.
📝 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
Object.keys(attributeMap).forEach((key) => {
const traitValue = traits[key];
if (traitValue) {
userTraits[attributeMap[key]] = traitValue;
}
}
});
// start with a safe, shallow copy to avoid mutating the input
const userTraits = traits && typeof traits === 'object' ? { ...traits } : {};
Object.keys(attributeMap).forEach((key) => {
const traitValue = traits?.[key];
// only skip null/undefined; keep 0/false
if (traitValue !== null && traitValue !== undefined) {
userTraits[attributeMap[key]] = traitValue;
}
});
🤖 Prompt for AI Agents
In src/v0/destinations/sendinblue/util.js around lines 122 to 127, the loop will
throw if traits is null/undefined and also drops legitimate falsy values
(0/false) due to the `if (traitValue)` check; update the code to safely handle
missing traits (e.g. guard with `traits` default or check `traits != null`) and
preserve falsy values by testing property presence (e.g. using
`Object.prototype.hasOwnProperty.call(traits, key)` or `key in traits`) before
assigning to userTraits; also consider ensuring attributeMap is non-falsy by
initializing it to `{}` where it’s created if needed.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Sep 29, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.78%. Comparing base (c0e7bda) to head (d6b0fd5).
⚠️ Report is 9 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4688      +/-   ##
===========================================
- Coverage    91.79%   91.78%   -0.01%     
===========================================
  Files          642      642              
  Lines        33998    33986      -12     
  Branches      8035     8033       -2     
===========================================
- Hits         31207    31195      -12     
+ Misses        2561     2539      -22     
- Partials       230      252      +22     

☔ 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.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)
2 New Code Smells (required ≤ 1)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@krishna2020
krishna2020 merged commit 05e12e7 into develop Sep 29, 2025
@krishna2020
krishna2020 deleted the revert-4684-fix/sendinBlue branch September 29, 2025 11:49
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.

5 participants