feat(stripe-mock): Add subscription_metadata and charge_metadata config#53596
feat(stripe-mock): Add subscription_metadata and charge_metadata config#53596arthurdedeus merged 2 commits intomasterfrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
f3277ef to
2eec6e4
Compare
Allows setting metadata separately per object type, so you can test the person resolution feature by putting posthog_person_distinct_id on subscriptions/charges without it being on the customer.
2eec6e4 to
910110e
Compare
|
| sub["latest_invoice"] = invoice["id"] | ||
|
|
||
| ch_idx = _next_id("ch") | ||
| charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})} |
There was a problem hiding this comment.
charge_metadata computed inside loop
Unlike customer_metadata and subscription_metadata (which are built once before the loop on lines 148–149), charge_metadata is recomputed on every monthly iteration even though neither self.cfg.charge_metadata nor persona_metadata changes during the loop. For consistency, hoist it alongside the other two metadata variables before the loop starts:
| charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})} | |
| charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})} |
(Add this line after line 149, and remove it from inside the loop.)
Prompt To Fix With AI
This is a comment left during a code review.
Path: services/stripe-mock/src/stripe_mock/data/scenarios.py
Line: 288
Comment:
**`charge_metadata` computed inside loop**
Unlike `customer_metadata` and `subscription_metadata` (which are built once before the loop on lines 148–149), `charge_metadata` is recomputed on every monthly iteration even though neither `self.cfg.charge_metadata` nor `persona_metadata` changes during the loop. For consistency, hoist it alongside the other two metadata variables before the loop starts:
```suggestion
charge_metadata = {**self.cfg.charge_metadata, **(persona_metadata or {})}
```
(Add this line after line 149, and remove it from inside the loop.)
How can I resolve this? If you propose a fix, please make it concise.
vdekrijger
left a comment
There was a problem hiding this comment.
The greptile comment seems fair, but since it's a mock I guess it's not that big of an issue 😄

Problem
The stripe-mock service applied
customer_metadatato all object types (customer, subscription, charge), making it impossibleto test scenarios where
posthog_person_distinct_idis set on subscriptions or charges but not on the customer.Part of #52270
Changes
subscription_metadataandcharge_metadataconfig fields to stripe-mock, each injected only into their respectiveobject type
How did you test this code?
Verified stripe-mock generates correct per-object metadata via local dev testing.
Publish to changelog?
No
Docs update
no