Repository navigation
Revert "fix: add validation for null/undefined traits" - #4688
Conversation
This reverts commit f909a8f.
Summary by CodeRabbit
WalkthroughRemoved 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggestions:
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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.
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. Comment |
There was a problem hiding this comment.
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 testsCall sites in
src/v0/destinations/sendinblue/transform.jsat lines 101, 139 and 243 invoketransformUserTraits(payload.attributes, …)ortransformUserTraits(payload.properties, …). After the recent revert:
- Ensure
transformUserTraitshandlesundefined/nullinput without throwing.- Preserve falsy values (
0,false), filtering onlynull/undefined.- Avoid mutating the original
traitsobject.Re-add tests for:
traits=undefined/nullreturns{}.- correct mapping when values are present.
- retention of
0/false; exclusion of onlynull/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 anddeletemutates 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
attributeMaphas any matching keys.)
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 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)
| Object.keys(attributeMap).forEach((key) => { | ||
| const traitValue = traits[key]; | ||
| if (traitValue) { | ||
| userTraits[attributeMap[key]] = traitValue; | ||
| } | ||
| } | ||
| }); |
There was a problem hiding this comment.
Prevent crash on undefined traits and preserve falsy (0/false) values
- If
traitsisundefined/null,traits[key]will throw. if (traitValue)drops legitimate values like0andfalse.
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
contactAttributeMappingcan be falsy, considerconst 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.
| 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.
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|




Reverts #4684