: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(data-warehouse): accept region-sharded Gladly organizations (#78983)
jake sciotto2330e3bf67d3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/gladly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/gladly.pyindex 4053c6718faf..cb0812d0e79d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/gladly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/gladly.py@@ -40,13 +40,17 @@ def _get_session(agent_email: str, api_token: str) -> requests.Session:def _clean_organization(organization: str) -> str:- """Accept either the bare org subdomain or a pasted full domain/URL."""+ """Accept the bare org subdomain, a region-qualified one like myorg.us-1, or a pasted full domain/URL."""org = organization.strip().removeprefix("https://").removeprefix("http://")- org = org.split(".")[0].split("/")[0]- if not re.fullmatch(r"[a-zA-Z0-9-]+", org):+ org = org.split("/")[0]+ if org.lower().endswith(".gladly.com"):+ org = org[: -len(".gladly.com")]+ # One optional extra label covers Gladly's region-sharded orgs (myorg.us-1.gladly.com);+ # the charset keeps the credentials pinned to a subdomain of gladly.com.+ if not re.fullmatch(r"[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)?", org):raise ValueError(- "Invalid Gladly organization. Use the first part of your Gladly URL, "- "with letters, digits, and hyphens only. For myorg.gladly.com enter myorg."+ "Invalid Gladly organization. Enter the part of your Gladly URL before .gladly.com. "+ "For myorg.gladly.com enter myorg. For myorg.us-1.gladly.com enter myorg.us-1.")return orgdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/source.pyindex 62004c3d966c..328a642eadf1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/source.py@@ -72,7 +72,7 @@ class GladlySource(ResumableSource[GladlySourceConfig, GladlyResumeConfig]):label="Gladly",caption="""Connect your Gladly account to pull your customer service data into the PostHog Data warehouse.-Your organization is the first part of your Gladly URL — for `myorg.gladly.com` enter `myorg`. The API token must belong to an agent with the API User permission (Settings > API Tokens). Data comes from Gladly's scheduled export jobs, which retain files for 14 days — history older than that requires asking Gladly support to regenerate exports.""",+Your organization is the part of your Gladly URL before `.gladly.com`. For `myorg.gladly.com` enter `myorg`, and for `myorg.us-1.gladly.com` enter `myorg.us-1`. The API token must belong to an agent with the API User permission (Settings > API Tokens). Data comes from Gladly's scheduled export jobs, which retain files for 14 days. History older than that requires asking Gladly support to regenerate exports.""",iconPath="/static/services/gladly.png",docsUrl="https://posthog.com/docs/cdp/sources/gladly",releaseStatus=ReleaseStatus.ALPHA,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/tests/test_gladly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/tests/test_gladly.pyindex a298cf1cca6e..74deb098e404 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/tests/test_gladly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gladly/tests/test_gladly.py@@ -56,12 +56,15 @@ class TestCleanOrganization:("https://myorg.gladly.com", "myorg"),("myorg.gladly.com/api/v1", "myorg"),("my-org", "my-org"),+ ("myorg.us-1", "myorg.us-1"),+ ("https://myorg.us-1.gladly.com", "myorg.us-1"),+ ("MYORG.GLADLY.COM", "MYORG"),],)def test_valid_organizations(self, value, expected):assert _clean_organization(value) == expected- @pytest.mark.parametrize("value", ["", "my org", "org?x=1"])+ @pytest.mark.parametrize("value", ["", "my org", "org?x=1", "myorg.us-1.extra"])def test_invalid_organizations_raise(self, value):with pytest.raises(ValueError):_clean_organization(value)