Skip to content

fix(data-warehouse): return a clear error for unknown source types when validating schemas - #68098

Merged
Gilbert09 merged 1 commit into
masterfrom
posthog-code/dw-schema-unknown-source-type
Jul 3, 2026
Merged

fix(data-warehouse): return a clear error for unknown source types when validating schemas#68098
Gilbert09 merged 1 commit into
masterfrom
posthog-code/dw-schema-unknown-source-type

Conversation

@Gilbert09

Copy link
Copy Markdown
Member

Problem

When Replay Vision watched real users go through the data-warehouse new-source onboarding flow, one recurring failure mode was an unknown source type reaching the backend (for example from a stale or malformed connect link where the source type had a trailing character).

The database_schema endpoint parses the source type with a bare ExternalDataSourceType(source_type) call. An unknown value raises a raw ValueError that is not a DRF exception, so it surfaces as an HTTP 500 with no message body instead of an actionable error. That is the endpoint the wizard hits on the "Link your data source" step, so a bad source type there just fails opaquely.

The sibling connect_link endpoint already guards the same parse and returns a clean 400 with Unknown source_type '<value>'.

Changes

Wrap the ExternalDataSourceType(source_type) parse in database_schema in a try/except ValueError and return a 400 with the same message shape connect_link uses. No behavior change for valid source types.

How did you test this code?

Added test_database_schema_unknown_source_type, which posts an unknown source type to the endpoint and asserts a 400 with the message body. Before this change that path raised a ValueError and returned a 500; the test locks in the 400. No existing test exercised database_schema with an unknown source type (only connect_link had one).

I (Claude) could not run the Django test suite in this environment — pytest and the backing databases are not provisioned here. I ran ruff check and ruff format --check over both touched files (both clean) and byte-compiled them. The change mirrors the already-tested connect_link guard exactly.

🤖 Agent context

Autonomy: Fully autonomous

I (Claude) found this while triaging session-replay summaries of the data-warehouse onboarding flow for low-risk friction fixes. I invoked /improving-drf-endpoints and /writing-tests while shaping the change. The fix is deliberately a straight copy of the existing connect_link guard rather than anything new, to keep it obviously correct and self-contained.

…en validating schemas

The database_schema endpoint parsed the source type with a bare
ExternalDataSourceType(source_type) call, so an unknown value raised a
raw ValueError and surfaced as an unhelpful 500 with no message body —
unlike the sibling connect_link endpoint, which already guards the parse
and returns a clean 400. Mirror that guard here so a bad source type
gives an actionable message instead of a server error.

Generated-By: PostHog Code
Task-Id: c6a89962-b4ea-425e-811d-6287f5c94495
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Hey @Gilbert09! 👋

It looks like your git author email on this PR isn't your @posthog.com address (owerstom@gmail.com). Since you're on the PostHog team, it's worth pointing your local git author email at your @posthog.com address. Why it matters:

  • Consistent work identity in git history — internal tooling that attributes commits to team members keys off your @posthog.com address.
  • Keeps team contributions easy to tell apart from external community ones when scanning history.

You can fix it for this repo with:

git config user.email "you@posthog.com"

Or set it globally with git config --global user.email "you@posthog.com". No need to redo this PR — just a nudge for next time. 🙂

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested review from a team July 3, 2026 02:00
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(data-warehouse): return a clear erro..." | Re-trigger Greptile

@Gilbert09 Gilbert09 added the stamphog Request AI approval (no full review) label Jul 3, 2026 — with PostHog

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial defensive fix adding a clear 400 error for unknown source types, with a matching test; author owns the code and two bot reviewers gave positive signals.

@Gilbert09
Gilbert09 merged commit 3009514 into master Jul 3, 2026
305 of 308 checks passed
@Gilbert09
Gilbert09 deleted the posthog-code/dw-schema-unknown-source-type branch July 3, 2026 08:48
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 3, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-03 09:17 UTC Run
prod-us ✅ Deployed 2026-07-03 09:38 UTC Run
prod-eu ✅ Deployed 2026-07-03 09:43 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant