fix(data-warehouse): return a clear error for unknown source types when validating schemas - #68098
Merged
Merged
Conversation
…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
Contributor
|
Hey @Gilbert09! 👋 It looks like your git author email on this PR isn't your
You can fix it for this repo with: git config user.email "you@posthog.com"Or set it globally with |
Contributor
|
Reviews (1): Last reviewed commit: "fix(data-warehouse): return a clear erro..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_schemaendpoint parses the source type with a bareExternalDataSourceType(source_type)call. An unknown value raises a rawValueErrorthat 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_linkendpoint already guards the same parse and returns a clean 400 withUnknown source_type '<value>'.Changes
Wrap the
ExternalDataSourceType(source_type)parse indatabase_schemain atry/except ValueErrorand return a 400 with the same message shapeconnect_linkuses. 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 aValueErrorand returned a 500; the test locks in the 400. No existing test exerciseddatabase_schemawith an unknown source type (onlyconnect_linkhad 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 checkandruff format --checkover both touched files (both clean) and byte-compiled them. The change mirrors the already-testedconnect_linkguard 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-endpointsand/writing-testswhile shaping the change. The fix is deliberately a straight copy of the existingconnect_linkguard rather than anything new, to keep it obviously correct and self-contained.