: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
feat(warehouse-sources): sync chargebee items and item prices (#105961)
posthog[bot]567ee01116ad
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.pyindex fb86d39d699d..1ba8f4a3de7a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.py@@ -73,6 +73,63 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {resource_version="Version number that increments whenever the invoice is modified, as a Unix timestamp in milliseconds.",),},+ "ItemPrices": {+ "description": "A price point for an item — the currency, billing period, and amount a plan, addon, or charge is sold at.",+ "docs_url": "https://apidocs.chargebee.com/docs/api/item_prices",+ "columns": _columns(+ item_id="Identifier of the item this price belongs to.",+ item_family_id="Identifier of the item family the item belongs to.",+ item_type="Type of the parent item: plan, addon, or charge.",+ name="Display name of the item price, visible only in Chargebee.",+ external_name="Display name of the item price shown to customers.",+ description="Description of the item price.",+ status="Status of the item price: active, archived, or deleted.",+ pricing_model="How the price is calculated: flat_fee, per_unit, tiered, volume, or stairstep.",+ price="Price of the item, in the smallest currency unit.",+ price_in_decimal="Price of the item in decimal form, for prices that need more precision.",+ currency_code="Three-letter ISO currency code the item price bills in.",+ period="Number of period units that make up one billing period.",+ period_unit="Unit of the billing period: day, week, month, or year.",+ trial_period="Length of the trial period offered with this item price.",+ trial_period_unit="Unit of the trial period: day or month.",+ billing_cycles="Number of billing cycles the item price applies for.",+ free_quantity="Quantity provided free of charge before the price applies.",+ is_taxable="Whether tax is applied to this item price.",+ tiers="Price tiers, for tiered, volume, and stairstep pricing models.",+ metadata="Custom key-value data stored against the item price.",+ price_variant_id="Identifier of the price variant this item price belongs to.",+ archived_at="Time at which the item price was archived, as a Unix timestamp.",+ resource_version="Version number that increments whenever the item price is modified, as a Unix timestamp in milliseconds.",+ deleted="Whether the item price has been deleted.",+ ),+ },+ "Items": {+ "description": "A product catalog entry — a plan, addon, or charge that customers can be billed for.",+ "docs_url": "https://apidocs.chargebee.com/docs/api/items",+ "columns": _columns(+ name="Display name of the item, visible only in Chargebee.",+ external_name="Display name of the item shown to customers.",+ description="Description of the item, visible only in Chargebee.",+ type="Type of the item: plan, addon, or charge.",+ status="Status of the item: active, archived, or deleted.",+ item_family_id="Identifier of the item family the item belongs to.",+ unit="Unit of measure for a quantity-based item, such as 'user' or 'GB'.",+ metered="Whether the item is billed on recorded usage.",+ usage_calculation="How usage is calculated for a metered item.",+ is_shippable="Whether the item is a physical product.",+ is_giftable="Whether gift subscriptions can be created for this item.",+ is_percentage_pricing="Whether the item is priced as a percentage of another amount.",+ included_in_mrr="Whether the item counts towards monthly recurring revenue.",+ item_applicability="Which addon and charge items can be applied to this plan item: all or restricted.",+ applicable_items="Addon and charge items that can be applied to this plan item, when applicability is restricted.",+ enabled_for_checkout="Whether customers can subscribe to this plan item through Checkout.",+ enabled_in_portal="Whether customers can change to this plan item in the Self-Serve Portal.",+ metadata="Custom key-value data stored against the item.",+ archived_at="Time at which the item was archived, as a Unix timestamp.",+ resource_version="Version number that increments whenever the item is modified, as a Unix timestamp in milliseconds.",+ deleted="Whether the item has been deleted.",+ ),+ },"Orders": {"description": "An order created from an invoice to fulfill physical or digital goods.","docs_url": "https://apidocs.chargebee.com/docs/api/orders",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.pyindex 07b63c3b279a..bbebba85c030 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.py@@ -105,6 +105,46 @@ def get_resource(},"table_format": "delta",},+ # Items and item prices have no `include_deleted` param; the list endpoints return+ # deleted records with `deleted: true` and `status: "deleted"`.+ "ItemPrices": {+ "name": "ItemPrices",+ "table_name": "item_prices",+ "write_disposition": {+ "disposition": "merge",+ "strategy": "upsert",+ }+ if should_use_incremental_field+ else "replace",+ "endpoint": {+ "data_selector": "list[*].item_price",+ "path": "/v2/item_prices",+ "params": {+ "updated_at[after]": incremental_param("updated_at") if apply_incremental_filter else None,+ "limit": 100,+ },+ },+ "table_format": "delta",+ },+ "Items": {+ "name": "Items",+ "table_name": "items",+ "write_disposition": {+ "disposition": "merge",+ "strategy": "upsert",+ }+ if should_use_incremental_field+ else "replace",+ "endpoint": {+ "data_selector": "list[*].item",+ "path": "/v2/items",+ "params": {+ "updated_at[after]": incremental_param("updated_at") if apply_incremental_filter else None,+ "limit": 100,+ },+ },+ "table_format": "delta",+ },"Orders": {"name": "Orders","table_name": "orders",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.pyindex 8233bf1735df..2f7d24150f6c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.py@@ -4,6 +4,8 @@ ENDPOINTS = ("Customers","Events","Invoices",+ "ItemPrices",+ "Items","Orders","Subscriptions","Transactions",@@ -13,6 +15,8 @@ INCREMENTAL_ENDPOINTS = ("Customers","Events","Invoices",+ "ItemPrices",+ "Items","Orders","Subscriptions","Transactions",@@ -43,6 +47,22 @@ INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {"field_type": IncrementalFieldType.Integer,},],+ "ItemPrices": [+ {+ "label": "updated_at",+ "type": IncrementalFieldType.DateTime,+ "field": "updated_at",+ "field_type": IncrementalFieldType.Integer,+ },+ ],+ "Items": [+ {+ "label": "updated_at",+ "type": IncrementalFieldType.DateTime,+ "field": "updated_at",+ "field_type": IncrementalFieldType.Integer,+ },+ ],"Orders": [{"label": "updated_at",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.pyindex e1abebca3a63..cee1c1af1661 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.py@@ -162,7 +162,10 @@ class TestChargebeeSourceResumeBehavior:list(cast(Iterable[Any], resource))return mock_session, sent_params- @pytest.mark.parametrize("endpoint", ["Customers", "Events", "Invoices", "Subscriptions", "Transactions", "Orders"])+ @pytest.mark.parametrize(+ "endpoint",+ ["Customers", "Events", "Invoices", "ItemPrices", "Items", "Subscriptions", "Transactions", "Orders"],+ )def test_fresh_run_saves_offset_after_each_non_terminal_page(self, endpoint: str) -> None:manager = MagicMock(spec=ResumableSourceManager)manager.can_resume.return_value = False@@ -265,6 +268,62 @@ class TestChargebeeSiteNameValidation:mock_validate.assert_not_called()+class TestChargebeeCatalogEndpoints:+ """`Items` and `ItemPrices` carry the product catalog that `subscription_items` points at.++ Their rows sit one level deeper than the response list, so a wrong `data_selector` or+ path yields an empty table rather than an error.+ """++ @pytest.mark.parametrize(+ ("endpoint", "path", "wrapper", "row"),+ [+ ("Items", "/v2/items", "item", {"id": "gold", "type": "plan", "metadata": {"seats": 10}}),+ (+ "ItemPrices",+ "/v2/item_prices",+ "item_price",+ {"id": "gold-USD-monthly", "item_id": "gold", "price": 1000},+ ),+ ],+ )+ def test_yields_the_nested_catalog_object(+ self, endpoint: str, path: str, wrapper: str, row: dict[str, Any]+ ) -> None:+ urls: list[str] = []+ response_iter = iter([_make_http_response({"list": [{wrapper: row}]})])++ def fake_send(request: Any, *_args: Any, **_kwargs: Any) -> Response:+ urls.append(request.url)+ return next(response_iter)++ manager = MagicMock(spec=ResumableSourceManager)+ manager.can_resume.return_value = False++ with patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client.make_tracked_session"+ ) as MockSession:+ mock_session = MockSession.return_value+ mock_session.headers = {}+ mock_session.prepare_request.side_effect = lambda req: req+ mock_session.send.side_effect = fake_send++ resource = chargebee_source(+ api_key="test-key",+ site_name="site-test",+ endpoint=endpoint,+ team_id=123,+ job_id="test_job",+ resumable_source_manager=manager,+ db_incremental_field_last_value=None,+ should_use_incremental_field=False,+ )+ yielded = list(cast(Iterable[Any], resource))++ assert urls == [f"https://site-test.chargebee.com/api{path}"]+ assert yielded == [[row]]++class TestChargebeeIncrementalFilter:"""The server-side cursor filter must only be sent once a real watermark exists (#76090).@@ -279,6 +338,8 @@ class TestChargebeeIncrementalFilter:"Customers": "updated_at[after]","Events": "occurred_at[after]","Invoices": "updated_at[after]",+ "ItemPrices": "updated_at[after]",+ "Items": "updated_at[after]","Orders": "updated_at[after]","Subscriptions": "updated_at[after]","Transactions": "updated_at[after]",