Repository navigation
fix: add validation for null/undefined traits - #4684
Conversation
Summary by CodeRabbit
WalkthroughAdds validation so transformUserTraits throws when traits are undefined, refactors the attribute mapping loop to a for-of iteration, and adds tests covering mapping, omission of falsy values, empty input, and the validation error. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Util as transformUserTraits
participant Refiner as refineUserTraits
Caller->>Util: transformUserTraits(traits, config)
alt traits is undefined
Util-->>Caller: throw InstrumentationError("Sendinblue: traits should be defined.")
else traits defined
note right of Util #DDEEFF: map configured keys\n(using for...of over attribute map)
Util->>Util: map traits per contactAttributeMapping\n(remove original keys, omit falsy)
Util->>Refiner: refineUserTraits(mappedTraits)
Refiner-->>Util: refinedTraits
Util-->>Caller: refinedTraits
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggestions
Pre-merge checks and finishing touches✅ Passed checks (3 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 |
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/v0/destinations/sendinblue/util.js (3)
123-125: Prefer explicit null/undefined check for intent clarity.Use a nullish check rather than generic falsy to match the stated requirement.
Apply this diff:
- if (!userTraits) { + if (userTraits == null) { throw new InstrumentationError('Sendinblue: traits should be defined.'); }Based on learnings
126-131: Avoid dropping valid falsy trait values (0/false).Current truthy check skips 0/false. If those should map through, use an explicit emptiness check.
Apply this diff:
- for (const key of Object.keys(attributeMap)) { - const traitValue = traits[key]; - if (traitValue) { - userTraits[attributeMap[key]] = traitValue; - } - } + for (const key of Object.keys(attributeMap)) { + const traitValue = traits[key]; + if (traitValue !== undefined && traitValue !== null && traitValue !== '') { + userTraits[attributeMap[key]] = traitValue; + } + }If Sendinblue attributes should omit only empty/null values but allow 0/false, this change is appropriate. Please confirm expected semantics. Based on learnings
121-121: Optional: avoid mutating the caller’s traits object.A shallow copy prevents side effects to inputs. If backward compatibility permits, consider copying.
Apply this diff:
- const userTraits = traits; + const userTraits = { ...traits };Based on learnings
src/v0/destinations/sendinblue/util.test.js (1)
32-36: Add a test for null traits as well.You cover undefined; include null to reflect the requirement.
Apply this diff:
test('throws when traits is undefined', () => { expect(() => transformUserTraits(undefined, contactAttributeMapping)).toThrow( 'Sendinblue: traits should be defined.', ); }); + + test('throws when traits is null', () => { + expect(() => transformUserTraits(null, contactAttributeMapping)).toThrow( + 'Sendinblue: traits should be defined.', + ); + });Based on learnings
📜 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(1 hunks)
🧰 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.test.jssrc/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 (2)
src/v0/destinations/sendinblue/util.test.js (1)
src/v0/destinations/sendinblue/util.js (7)
require(1-1)require(3-3)require(4-10)require(11-11)require(12-15)require(17-17)transformUserTraits(117-134)
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). (7)
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User 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 (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
src/v0/destinations/sendinblue/util.test.js (3)
9-17: LGTM: mapping + removal covered.Covers key rename and cleanup correctly.
19-24: LGTM: falsy value behavior captured.Matches current implementation (skips '', null).
26-30: LGTM: empty object case validated.Confirms empty object passes through unchanged, consistent with code.
src/v0/destinations/sendinblue/util.js (1)
117-134: No issues with transformUserTraits call sites
All invocations in sendinblue/transform.js use payload.attributes or payload.properties from constructPayload, which always yields an object (defaulting to {}). The new fail-fast check won’t trigger unexpectedly.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4684 +/- ##
========================================
Coverage 91.79% 91.79%
========================================
Files 642 642
Lines 33998 34007 +9
Branches 8035 8044 +9
========================================
+ Hits 31207 31216 +9
+ Misses 2561 2539 -22
- Partials 230 252 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Allure Test reports for this run are available at:
|
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2920210 to
67f217c
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/v0/destinations/sendinblue/util.js (1)
122-125: Tighten null/undefined check and add null unit testReplace the loose falsy guard with an explicit null/undefined check:
- if (!userTraits) { + if (userTraits === null || userTraits === undefined) { throw new InstrumentationError('Sendinblue: traits should be defined.'); }Add a unit test for
null:test('throws when traits is null', () => { expect(() => transformUserTraits(null, contactAttributeMapping) ).toThrow('Sendinblue: traits should be defined.'); });Optional: move this validation just before destructuring/aliasing for clarity.
📜 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(1 hunks)
🚧 Files skipped from review as they are similar to previous 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 AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/sendinblue/util.js (1)
126-131: Loop refactor LGTM; behavior preserved.Iterating
Object.keys(attributeMap)with afor...ofretains the original semantics and keeps the mapping logic clear. No issues found.
|
Allure Test reports for this run are available at:
|
|



Add validation for null/undefined traits in Sendinblue (Brevo) destination
What are the changes introduced in this PR?
transformUserTraitsto throw a clear error whentraitsis undefined (null/undefined), preventing runtime crashes during track processing.transformUserTraitsloop style for clarity while preserving behavior for valid inputs.Changed files:
src/v0/destinations/sendinblue/util.jsWhat is the related Linear task?
Link: https://linear.app/rudderstack/issue/INT-4194/add-validation-for-nullundefined-traits-in-sendingblue-destination
Please explain the objectives of your changes below
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
traitsundefined, leading to runtime errors (e.g., “Cannot convert undefined or null to object”) deeper in the flow.traitsis not provided totransformUserTraits. This avoids obscure transformation crashes and ensures consistent error semantics.Impact:
Any new dependencies introduced with this change?
Any new generic utility introduced or modified. Please explain the changes.
transformUserTraits(traits, contactAttributeMapping):InstrumentationError('Sendinblue: traits should be defined.')iftraitsis undefined.refineUserTraits.Any technical or performance related pointers to consider with the change?
@coderabbitai review
Developer checklist
Reviewer checklist