PostHog / PostHog/posthog

Workflows: expose the active relationship assignment date on the external account payload

Open
#76,074 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature/customer-analytics
Dominant language
Python
Stars
39.9k
Forks
3.4k
Avg merge
6h 51m
Merged PRs (30d)
232

Description

TL;DR

AccountRelationship stores when a CSM/AE/owner assignment started, and the internal facade exposes that date. The external account payload that workflows consume collapses relationships to {definition_name: [{user_id, email}]} with no dates. A workflow cannot read when a role was assigned. Scope: add the active assignment's started_at to the external payload. Exposing full assignment history is out of scope.

What exists today

  • AccountRelationship carries started_at and ended_at (products/customer_analytics/backend/models/relationship.py:48-49). assign() closes the previous holder's row (ended_at = now()) and inserts a new one when the definition is single-holder (logic/relationships.py:28-53), so started_at on the active row is the date of the current assignment.
  • The internal contract exposes the date: contracts.AccountRelationship has started_at: datetime (facade/contracts.py:55-63), returned by list_account_relationships (facade/api.py:2800-2812).
  • The external wire shape drops it: _to_external_account (facade/api.py:318-339) builds relationships as {definition_name: [{user_id, email}]} from active rows only (ended_at__isnull=True). This is the payload of GET /api/customer_analytics/external/account?external_id= (presentation/views/external.py:188-197).
  • Workflows read account data through that payload: the "Get account" step (template-posthog-get-account, nodejs/src/cdp/templates/_destinations/posthog_customer_analytics/posthog-get-account.template.ts) fetches it and maps response paths into workflow variables (#69417 added custom_properties to the payload the same way). Any field absent from the payload is not pickable as a variable.

Constraints

  • The relationship table is a shadow of the JSON role keys (csm, account_executive, account_owner) on Account._properties. The JSON is authoritative, and sync_from_account_properties() keeps the table in step from every JSON writer (products/customer_analytics/backend/COMPROMISES.md:38-63). The table is the only place assignment dates exist. The JSON keys carry no dates.
  • The _to_external_account docstring notes the payload was kept byte-identical to what the CDP worker consumed before the facade move (facade/api.py:319-324). Existing workflow output variables reference literal result paths into relationships ({definition_name: [{user_id, email}]}), so entry shape changes are visible to saved workflows.

Goal

A workflow can read the date the active relationship (for example CSM or AE) was assigned to an account, as a pickable output variable of the Get account step.

Open questions

  • Relationships are keyed by definition name in the external payload. Is that keying stable enough for date fields, given result paths in workflow output variables reference it literally?
  • Where does the date surface in the Get account step's variable picker: only via the response tree, or as a pre-populated output variable alongside the existing hardcoded relationship entries (products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.ts)?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with _to_external_account and the external account view in facade/api.py and presentation/views/external.py, then inspect the Get account template and customer_analytics.ts registry. Trace how active AccountRelationship rows become workflow variables and how existing relationship result paths are preserved. Done means the active assignment date is available to workflows without removing or changing existing relationship fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.