:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(stripe): pass required filter param inside params for flat nested resources (#75720)
Tom Owers0c549b0a8fd4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.pyindex 4847df2a8625..49aefec7dc1b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py@@ -1,5 +1,6 @@import osimport re+import inspectimport dataclassesfrom collections.abc import Callable, Mappingfrom typing import Any, Literal, Optional, Union, cast, get_args, get_type_hints@@ -641,6 +642,11 @@ def get_rows(resource.parent.method,params={**default_params, **resource.parent.params, **resume_params},)+ # Path-scoped services (e.g. customers.payment_methods.list) take the parent id as a+ # method keyword, while flat services with a required filter (e.g.+ # entitlements.active_entitlements.list) accept it only inside `params`. Route by the+ # method's actual signature so both shapes get the parent id where Stripe expects it.+ parent_param_is_kwarg = resource.nested_parent_param in inspect.signature(resource.method).parametersskipped_parents = 0for obj in stripe_parent_objects.auto_paging_iter():parent_obj_id = obj[resource.parent_id]@@ -650,11 +656,17 @@ def get_rows(skipped_parents += 1continueparent_params = resource.nested_params_from_parent(obj) if resource.nested_params_from_parent else {}+ nested_params = {**default_params, **resource.params, **parent_params}+ nested_kwargs: dict[str, Any] = {}+ if parent_param_is_kwarg:+ nested_kwargs[resource.nested_parent_param] = parent_obj_id+ else:+ nested_params[resource.nested_parent_param] = parent_obj_idtry:stripe_nested_objects = _call_stripe(resource.method,- **{resource.nested_parent_param: parent_obj_id},- params={**default_params, **resource.params, **parent_params},+ params=nested_params,+ **nested_kwargs,)for nested_obj in stripe_nested_objects.auto_paging_iter():batcher.batch(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.pyindex 9a392eb5f82d..5a33391334b6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py@@ -426,6 +426,21 @@ class TestStripeNestedResourceGetRows:assert called_for == ["cus_credit", "cus_owed"]assert {row["customer"] for row in rows} == {"cus_credit", "cus_owed"}+ def test_query_param_service_receives_parent_in_params(self):+ # Flat Stripe services with a required filter (e.g. entitlements.active_entitlements.list)+ # expose the parent only inside `params`, not as a method keyword — passing it as a kwarg+ # raised TypeError: unexpected keyword argument.+ seen_customers: list[str] = []++ def nested_method(params=None):+ seen_customers.append(params["customer"])+ return _list_object([{"id": f"ent_{params['customer']}"}])++ rows = _run_nested_get_rows(nested_method, parent_objects=[{"id": "cus_a"}, {"id": "cus_b"}])++ assert seen_customers == ["cus_a", "cus_b"]+ assert {row["customer"] for row in rows} == {"cus_a", "cus_b"}+class TestInvoiceListWithAllLines:def test_skips_lines_for_invoice_deleted_mid_sync(self):