-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Feature/catch notsupported exception #7573
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?
Feature/catch notsupported exception #7573
Conversation
- Add NotSupported exception handling to refresh_schema() - Log unsupported datasources at DEBUG level - Avoid error metrics for datasources without schema support
- Test that NotSupported exceptions are caught and logged at DEBUG level - Verify no warning logs are generated for unsupported datasources
|
Thank you for your PR! I just feel that the test is too much as the test is testing only logging for this 3 lines of code. How about ? |
|
And, this is just my curious. And, I'm sorry if it is my mistaken. |
As suggested by @yoshiokatsuneo, testing logging details for 3 lines of code is excessive and may hurt maintainability. The existing tests already ensure the functionality works correctly.
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 implements cleaner error handling for datasources that don't support schema refresh by catching NotSupported exceptions and logging them at DEBUG level instead of WARNING level. This approach is simpler and more maintainable than the alternative of pre-filtering datasource types.
Key changes:
- Added
NotSupportedexception handler inrefresh_schema()task that logs at DEBUG level without incrementing error metrics - Added unit test to verify the NotSupported exception is handled correctly
- Maintains exception ordering (NotSupported caught before generic Exception)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| redash/tasks/queries/maintenance.py | Added NotSupported import and exception handler that logs at DEBUG level without incrementing error metrics |
| tests/tasks/test_refresh_schemas.py | Added test case to verify NotSupported exceptions are logged at DEBUG level and don't trigger warning logs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/tasks/test_refresh_schemas.py
Outdated
| def test_handles_notsupported_exception(self): | ||
| ds = self.factory.data_source | ||
| with patch.object(ds, "get_schema", side_effect=NotSupported("Schema not supported")): | ||
| with patch("redash.tasks.queries.maintenance.logger") as mock_logger: | ||
| refresh_schema(ds.id) | ||
| mock_logger.debug.assert_called_once() | ||
| mock_logger.warning.assert_not_called() |
Copilot
AI
Dec 13, 2025
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.
The test should verify that no error metric is incremented when NotSupported exception is raised. This is a key behavior that distinguishes NotSupported from other exceptions (line 185 increments the error metric for general exceptions, but line 181-182 should not increment any metric). Consider adding an assertion to check that statsd_client.incr was not called with "refresh_schema.error".
4b5ca90 to
a29616b
Compare
|
Thank you for the feedback! Regarding the test: I've removed the added test as you suggested. You're absolutely right that testing logging details for 3 lines of code is excessive. Regarding AI usage: Yes, I am using AI assistance. The test was added based on my instruction, following the PR template's "How is this tested?" section which includes "Unit tests (pytest, jest)" as an option. I wanted to ensure comprehensive testing coverage, but I understand now that it was overkill for this minimal change. The PR now contains only the essential 3-line change to handle NotSupported exceptions. |
|
Thank you for updated PR, and the detailed comment. Thank you ! |
|
(Now, I think you can just click "Squash and Merge" button whenever you want to merge. ) |
What type of PR is this?
Description
This PR implements an alternative approach to #7572 by catching
NotSupportedexceptions inrefresh_schema()instead of pre-filtering datasource types.Addresses issue #7571 - Clean up error logs from datasources that don't support schema refresh.
Motivation
As suggested by @yoshiokatsuneo in PR #7572 review, this approach is simpler and more maintainable:
Changes
NotSupportedexception handling torefresh_schema()Files changed:
redash/tasks/queries/maintenance.py: +3 lines (1 import, 2 exception handling)tests/tasks/test_refresh_schemas.py: +10 lines (1 test case)Flow Diagram
flowchart TD Start([refresh_schemas]) --> Loop{For each<br/>datasource} Loop -->|Paused| Skip1[Skip: paused] Loop -->|Active| Queue[Enqueue refresh_schema job] Queue --> Worker[Worker executes job] Worker --> Try[Try: ds.get_schema refresh=True] Try -->|Success| Success[Log: state=finished<br/>Increment: success metric] Try -->|JobTimeoutException| Timeout[Log: state=timeout<br/>Increment: timeout metric] Try -->|NotSupported| NotSupp[Log DEBUG: not supported<br/>No metric increment] Try -->|Other Exception| Error[Log WARNING: failed<br/>Increment: error metric] Success --> JobOK1[Job OK] Timeout --> JobOK2[Job OK] NotSupp --> JobOK3[Job OK] Error --> JobOK4[Job OK] Skip1 --> Loop JobOK1 --> Loop JobOK2 --> Loop JobOK3 --> Loop JobOK4 --> Loop Loop -->|Done| End([End]) style NotSupp fill:#2d5016,stroke:#4a7c2c,color:#fff style Success fill:#1e4d7b,stroke:#2e6da4,color:#fff style Error fill:#8b2e3b,stroke:#c9302c,color:#fff style Timeout fill:#8b6914,stroke:#d9a441,color:#fffKey Points:
How is this tested?
Unit Tests
Manual Testing
Tested with 3 datasources:
Worker logs (INFO level):
No error logs, all jobs completed successfully.
DEBUG Log Verification
When DEBUG level is enabled, unsupported datasources are logged:
Comparison with PR #7572
REDASH_SCHEMAS_REFRESH_EXCLUDED_TYPESBenefits
Log Output Behavior
Related Tickets & Documents
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
N/A - Backend changes only