Skip to content

fix(data-imports): handle sources without schema discovery in database_schema - #68114

Merged
Gilbert09 merged 2 commits into
masterfrom
posthog-code/database-schema-notimplemented-graceful
Jul 3, 2026
Merged

fix(data-imports): handle sources without schema discovery in database_schema#68114
Gilbert09 merged 2 commits into
masterfrom
posthog-code/database-schema-notimplemented-graceful

Conversation

@Gilbert09

Copy link
Copy Markdown
Member

Problem

Error tracking surfaced a NotImplementedError with no message, captured as an unexpected server error, coming out of the data-warehouse import pipeline:

  • Raised in get_schemas at products/warehouse_sources/backend/temporal/data_imports/sources/common/base.py
  • Reached through the database_schema API endpoint (ExternalDataSourceViewSet.database_schema)
  • Triggered for an unreleased source type

Issue: https://us.posthog.com/project/2/error_tracking/019f261a-ca75-75a3-9837-182e94289ce6

The base _BaseSource.get_schemas raises a bare NotImplementedError for any source that doesn't implement schema discovery (unreleased stubs that inherit SimpleSource directly, e.g. Amazon CloudWatch). The database_schema endpoint wrapped the get_schemas call in a broad except Exception, and since a bare NotImplementedError matches none of the expected-error patterns in _classify_refresh_schemas_error, it fell through to capture_exception and returned the generic "Could not fetch schemas from source." message.

This is our code being fragile, not a user credential or upstream problem. There is nothing to retry — the source simply has no schema discovery — so it should degrade gracefully rather than page us.

Changes

Add an except NotImplementedError branch to database_schema that returns a clean 400 with a clear message and does not capture the exception. This mirrors the guard the sibling setup endpoint already has for the same base NotImplementedError, so the two schema-discovery entry points now behave consistently.

No behavior change for sources that implement get_schemas.

How did you test this code?

Added test_database_schema_rejects_source_without_schema_discovery, which posts a source type that inherits the base get_schemas to the endpoint and asserts a 400 with the friendly message and that capture_exception is not called. Before this change that path captured the NotImplementedError and returned the generic fallback message. No existing test covered database_schema for a source without schema discovery — the sibling case (test_setup_rejects_source_without_schema_discovery) only exercises the setup endpoint, and test_database_schema_captures_only_unexpected_source_errors mocks get_schemas rather than raising the real base error.

I (Claude) could not run the Django test suite in this environment — pytest's backing databases are not provisioned here (the pre-existing sibling test fails the same way on connection). I ran ruff check and ruff format --check over both touched files (both clean), and statically verified the source hierarchy: AmazonCloudWatchSource inherits SimpleSource without overriding get_schemas, so the base raises NotImplementedError. The new test mirrors the already-passing setup guard test.

🤖 Agent context

Autonomy: Fully autonomous

I (Claude) found this while triaging an error-tracking issue in the data-warehouse import pipeline. I confirmed the issue via the PostHog error-tracking tools (full stack trace, single occurrence, top in-app frame at base.py get_schemas), traced the call path from database_schema into the shared base source, and classified it as a fixable fragility rather than a user/upstream error worth adding to NonRetryableErrors.

I invoked /improving-drf-endpoints and /writing-tests while shaping the change. I chose the view-layer fix (rather than touching the shared base or the classifier) because the setup endpoint already establishes exactly this pattern for the same exception, so mirroring it keeps the two entry points consistent and the change obviously correct. I checked open PRs (including the maintainer's own) for duplicates: #68098 guards the same endpoint but for a different root cause (unknown source type raising ValueError), and #67605 touches the setup path and MCP classification, not this get_schemas call site.

…e_schema

The database_schema endpoint called source.get_schemas() inside a broad
try/except that ran every non-classified exception through capture_exception.
Unreleased sources inherit the base get_schemas, which raises a bare
NotImplementedError, so hitting the endpoint for one surfaced as captured
error-tracking noise instead of an actionable response.

Add an except NotImplementedError branch that returns a clean 400 without
capturing, mirroring the existing guard in the sibling setup endpoint.

Generated-By: PostHog Code
Task-Id: 3404976d-6fb3-4da8-8559-e268cc3f0e85
@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 06:17
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(data-imports): handle sources withou..." | Re-trigger Greptile

…test

Switch the database_schema NotImplementedError test from the unreleased
AmazonCloudWatch source to AmazonS3, whose get_schemas omission is deliberate
and stable. Mirrors the sibling setup test and avoids silently losing branch
coverage if an unreleased source later implements schema discovery.

Generated-By: PostHog Code
Task-Id: 3404976d-6fb3-4da8-8559-e268cc3f0e85
@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.

Small, well-scoped fix by an owning-team author that gracefully handles NotImplementedError from schema discovery; the reviewer's test-coupling concern was addressed and acknowledged with a 👍, no outstanding issues.

@Gilbert09
Gilbert09 merged commit e40f296 into master Jul 3, 2026
256 checks passed
@Gilbert09
Gilbert09 deleted the posthog-code/database-schema-notimplemented-graceful branch July 3, 2026 08:49
@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