Skip to content

fix: check on traits and traits.context - #4682

Merged
lvrach merged 3 commits into
rudderlabs:external/ThabetIbrahim/fix-identify-payloadfrom
ThabetIbrahim:fix-identify-payload
Oct 6, 2025
Merged

lvrach merged 3 commits into
rudderlabs:external/ThabetIbrahim/fix-identify-payloadfrom
ThabetIbrahim:fix-identify-payload

Conversation

@ThabetIbrahim

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

Write a brief explainer on your code changes.

Checking user traits for both .message.context.traits as well as .message.traits

What is the related Linear task?

N/A

Please explain the objectives of your changes below

When users send an identify request to Cloud integration, in some cases, they opt to include the traits inside the payload itself rather than the context, causing those properties to get dropped.

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

@ThabetIbrahim
ThabetIbrahim requested a review from a team as a code owner September 25, 2025 10:27
@coderabbitai

coderabbitai Bot commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Improvements

    • Consolidated user trait handling for more consistent mapping across Identify events.
    • Company data is derived from user traits when available, improving payload accuracy.
    • Updated metadata extraction for reliability.
    • Track and Group event behavior remains unchanged.
  • Bug Fixes

    • Identify events no longer rely on a single traits source, preventing missing or null company data.
    • Sends company details only when present, avoiding null/undefined errors in payloads.

Walkthrough

Consolidates user traits sourcing from message.traits or message.context.traits, derives companyTraits from userTraits.company, updates Identify payload to null-check companyTraits.id and pass either the full companyTraits or null, and shifts trait transformation and metadata extraction to use userTraits. Track and Group logic unchanged.

Changes

Cohort / File(s) Summary
Userpilot Identify workflow
src/cdk/v2/destinations/userpilot/procWorkflow.yaml
Consolidate userTraits from message.traits or message.context.traits; derive companyTraits from userTraits.company; update Identify payload to check companyTraits.id and include full companyTraits or null; route trait transformation and metadata extraction to userTraits; Track/Group flows unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Src as Source
  participant WF as procWorkflow.yaml
  participant UP as Userpilot API

  rect rgba(200,220,255,0.25)
    note over WF: Identify flow
    Src->>WF: message (Identify)
    WF->>WF: userTraits = message.traits || message.context.traits
    WF->>WF: companyTraits = userTraits.company
    alt companyTraits && companyTraits.id
      WF->>UP: Identify payload { user: userTraits, company: companyTraits }
      Note right of UP: Company included
    else no company id
      WF->>UP: Identify payload { user: userTraits, company: null }
      Note right of UP: Company omitted
    end
  end

  rect rgba(220,255,220,0.15)
    note over WF: Track / Group flows
    Src-->>WF: message (Track/Group)
    WF-->>UP: Unchanged payload logic
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • vinayteki95
  • koladilip

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title “fix: check on traits and traits.context” succinctly indicates that the change addresses trait checking logic and is directly related to the core update of inspecting both payload-level traits and context-level traits, thereby aligning with the main intent of the pull request.
Description Check ✅ Passed The PR description faithfully follows the repository’s template by including the required sections—change summary, related task, objectives, capability impacts, dependency notes, and developer/reviewer checklists—and it clearly explains why inspecting both message.context.traits and message.traits is necessary.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent 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 4cf9d2f and 941f83e.

📒 Files selected for processing (1)
  • src/cdk/v2/destinations/userpilot/procWorkflow.yaml (1 hunks)
🔇 Additional comments (1)
src/cdk/v2/destinations/userpilot/procWorkflow.yaml (1)

38-47: Still merging one traits source only — despite the update, the code grabs the first non-null traits object and drops the other. When both message.context.traits (with company) and message.traits (with fresh user properties) arrive together—as happens today—we’ll silently discard whichever one isn’t chosen. That reintroduces the data loss this PR set out to fix. Please merge the two objects (e.g., { ...contextTraits, ...rootTraits }) so every field survives, then derive companyTraits off the merged result with a fallback for legacy payloads.


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.

@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

📜 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 e6acf3e and 4cf9d2f.

📒 Files selected for processing (1)
  • src/cdk/v2/destinations/userpilot/procWorkflow.yaml (1 hunks)

Comment on lines +38 to +40
const userTraits = .message.traits ?? .message.context.traits ?? {};
const companyTraits = userTraits.company ?? {};

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 | 🟠 Major

Preserve traits from both message.traits and message.context.traits.

Picking whichever object is non-null means we drop any fields (notably company) that may exist only under context.traits whenever message.traits is present—even if it’s just {}. That regresses existing payloads where company data still lives under context.traits. Please merge both sources and only fall back when a source is absent.

-      const userTraits = .message.traits ?? .message.context.traits ?? {};
-      const companyTraits = userTraits.company ?? {};
+      const contextTraits = (.message.context && .message.context.traits) ?? {};
+      const rootTraits = .message.traits ?? {};
+      const userTraits = { ...contextTraits, ...rootTraits };
+      const companyTraits = userTraits.company ?? contextTraits.company ?? {};
📝 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
const userTraits = .message.traits ?? .message.context.traits ?? {};
const companyTraits = userTraits.company ?? {};
const contextTraits = (.message.context && .message.context.traits) ?? {};
const rootTraits = .message.traits ?? {};
const userTraits = { ...contextTraits, ...rootTraits };
const companyTraits = userTraits.company ?? contextTraits.company ?? {};
🤖 Prompt for AI Agents
In src/cdk/v2/destinations/userpilot/procWorkflow.yaml around lines 38 to 40,
the code currently picks one traits object and drops fields from the other;
instead merge message.traits and message.context.traits so fields from both are
preserved (e.g., company under context.traits), then derive companyTraits from
the merged object with a fallback to {}. Ensure the merge treats undefined
sources as empty objects and does not mutate originals.

@codecov

codecov Bot commented Sep 25, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (external/ThabetIbrahim/fix-identify-payload@05e12e7). Learn more about missing BASE report.

Additional details and impacted files
@@                              Coverage Diff                               @@
##             external/ThabetIbrahim/fix-identify-payload    #4682   +/-   ##
==============================================================================
  Coverage                                               ?   91.79%           
==============================================================================
  Files                                                  ?      645           
  Lines                                                  ?    34086           
  Branches                                               ?     8051           
==============================================================================
  Hits                                                   ?    31290           
  Misses                                                 ?     2566           
  Partials                                               ?      230           

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

@koladilip koladilip 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.

change looks fine

@koladilip

Copy link
Copy Markdown
Contributor

Currently we are in process updating CI CD so we will create another PR from our side this change. Later will update our contributing guide with the new changes.

@lvrach
lvrach changed the base branch from develop to external/ThabetIbrahim/fix-identify-payload October 6, 2025 10:54
@lvrach
lvrach merged commit 6ffc4c5 into rudderlabs:external/ThabetIbrahim/fix-identify-payload Oct 6, 2025
koladilip pushed a commit that referenced this pull request Oct 6, 2025
* fix: check on traits and traits.context

* prioritize message.context.traits

Co-authored-by: ThabetIbrahim <[email protected]>
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.

4 participants