-
Notifications
You must be signed in to change notification settings - Fork 16.2k
fix(charts): add query_context validation to prevent incomplete metadata #36076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…chema and ChartPutSchema
Code Review Agent Run #50c92eActionable Suggestions - 0Additional Suggestions - 10
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Duplicate JSON validation logic ▹ view | ||
| Imperative field validation ▹ view | ||
| Falsy JSON strings incorrectly bypass validation ▹ view | ||
| Inefficient field validation with list collection ▹ view |
Files scanned
| File Path | Reviewed |
|---|---|
| superset/utils/schema.py | ✅ |
| superset/charts/schemas.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #36076 +/- ##
===========================================
+ Coverage 0 69.11% +69.11%
===========================================
Files 0 632 +632
Lines 0 47959 +47959
Branches 0 5467 +5467
===========================================
+ Hits 0 33146 +33146
- Misses 0 13536 +13536
- Partials 0 1277 +1277
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ying missing fields check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds validation to the query_context field in chart schemas to ensure it contains required metadata (datasource and queries) when provided, preventing runtime errors from incomplete query context data.
- Created a new
validate_query_context_metadata()function that validates both JSON structure and required fields - Updated
ChartPostSchemato use the new validator (replacing genericvalidate_json) - Updated
ChartPutSchemato add the new validator (previously had no validation) - Added comprehensive unit and integration tests
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| superset/utils/schema.py | Adds validate_query_context_metadata() function to validate query_context JSON structure and required fields |
| superset/charts/schemas.py | Updates ChartPostSchema and ChartPutSchema to use the new validator for query_context field |
| tests/unit_tests/utils/test_schema.py | Adds comprehensive unit tests for the new validator covering valid/invalid cases, edge cases, and error messages |
| tests/unit_tests/charts/test_schemas.py | Adds integration tests verifying schema-level validation for both POST and PUT operations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've completed my review and didn't find any issues.
Files scanned
| File Path | Reviewed |
|---|---|
| superset/utils/schema.py | ✅ |
| superset/charts/schemas.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
|
Running CI, but I think i defer to @betodealmeida here :D |
SUMMARY
This PR adds comprehensive validation for the
query_contextfield in bothChartPostSchemaandChartPutSchemato ensure that when provided, it contains the required metadata fields (datasourceandqueries) needed for chart data retrieval.Changes:
validate_query_context_metadata()function insuperset/utils/schema.pythat validates the structure of query_context JSONChartPostSchemato use the new validator (previously used genericvalidate_json)ChartPutSchemato add the new validator (previously had no validation)tests/unit_tests/utils/test_schema.pytests/unit_tests/charts/test_schemas.pyto verify schema-level validationRationale:
Previously, the
query_contextfield only validated that the value was valid JSON, but didn't ensure it contained the necessary structure for chart operations. This could lead to runtime errors when charts are rendered with incomplete query context data. The new validation ensures data integrity at the API level.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Backend validation change with no UI impact
TESTING INSTRUCTIONS
Run the unit tests:
Manual API testing (optional):
/api/v1/chart/) with invalid query_context (missingdatasourceorqueries)nullquery_context - should succeed (field is nullable)Verify pre-commit hooks pass:
git add . pre-commit runADDITIONAL INFORMATION