Repository navigation
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.
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.
| 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() |
There was a problem hiding this comment.
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. ) |
|
Thank you for the review. Merged. |
* master: (69 commits) Update Python version to 3.13 (getredash#7636) Update plotly.js to 3.3.1, react-pivottable to 0.11.0 (getredash#7634) Add charset option to RDS MySQL datasource (getredash#7616) Aggregate y value for same x (getredash#7631) fix(mysql): Change default charset to utf8mb4 (getredash#7615) Update packages for compatibility with setuptools 82 (getredash#7622) Snapshot: 26.02.0-dev chore: support ipv6 for server in docker (getredash#7596) Add impersonation option in trino datasource (getredash#7605) Fix Elasticsearch connector configuration key mismatch (getredash#7607) duckdb: Show catalog (database) where applicable (e.g. Motherduck) (getredash#7599) Snapshot: 26.01.0-dev Feature/catch notsupported exception (getredash#7573) Multi-org: format base path, not including protocol (getredash#7260) fix(destinations): Handle unicode characters in webhook notifications (getredash#7586) Persist updated values and apply saved dashboard parameters (getredash#7570) Add ibm-db package to enable DB2 as datasource: (getredash#7581) Snapshot: 25.12.0-dev PostgreSQL: allow connection parameters to be specified (getredash#7579) Add lineShape option for Line and Area charts (getredash#7582) ...
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