Skip to content

Commit d479656

Browse files
committed
Move the custom database errors to a separate config file
1 parent b202ce8 commit d479656

File tree

3 files changed

+57
-29
lines changed

3 files changed

+57
-29
lines changed

docs/docs/configuration/databases.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ You can use the `Extra` field in the **Edit Databases** form to configure SSL:
17701770
}
17711771
```
17721772
##### Custom Error Messages
1773-
You can use the ``CUSTOM_DATABASE_ERRORS`` setting in your ``superset_config.py`` to configure custom error messages for database exceptions.
1773+
You can use the `CUSTOM_DATABASE_ERRORS` in the `superset/custom_database_errors.py` file or overwrite it in your config file to configure custom error messages for database exceptions.
17741774

17751775
This feature lets you transform raw database errors into user-friendly messages, optionally including documentation links and hiding default error codes.
17761776

@@ -1794,7 +1794,7 @@ CUSTOM_DATABASE_ERRORS = {
17941794
}
17951795
)
17961796
},
1797-
"postgres": {}
1797+
"PostgreSQL": {}
17981798
}
17991799
```
18001800

superset/config.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
from superset.advanced_data_type.plugins.internet_port import internet_port
5353
from superset.advanced_data_type.types import AdvancedDataType
5454
from superset.constants import CHANGE_ME_SECRET_KEY
55-
from superset.errors import SupersetErrorType
5655
from superset.jinja_context import BaseTemplateProcessor
5756
from superset.key_value.types import JsonKeyValueCodec
5857
from superset.stats_logger import DummyStatsLogger
@@ -2153,33 +2152,13 @@ class ExtraDynamicQueryFilters(TypedDict, total=False):
21532152
# keeping a web API call open for this long.
21542153
SYNC_DB_PERMISSIONS_IN_ASYNC_MODE: bool = False
21552154

2156-
# CUSTOM_DATABASE_ERRORS: Configure custom error messages for database exceptions.
2155+
# CUSTOM_DATABASE_ERRORS: Configure custom error messages for database exceptions
2156+
# in superset/custom_database_errors.py.
21572157
# Transform raw database errors into user-friendly messages with optional documentation
2158-
# links using custom_doc_links. Set show_issue_info=False to hide default error codes.
2159-
# Example:
2160-
# CUSTOM_DATABASE_ERRORS = {
2161-
# "trino": {
2162-
# re.compile(r'message="(?P<message>[^"]*)"'): (
2163-
# __(
2164-
# 'Unexpected error: "%(message)s"'
2165-
# ),
2166-
# SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
2167-
# {
2168-
# "custom_doc_links": [
2169-
# {
2170-
# "url": "https://example.com/docs/1",
2171-
# "label": "Check documentation"
2172-
# },
2173-
# ],
2174-
# "show_issue_info": False,
2175-
# }
2176-
# )
2177-
# }
2178-
# }
2179-
2180-
CUSTOM_DATABASE_ERRORS: dict[
2181-
str, dict[re.Pattern[str], tuple[str, SupersetErrorType, dict[str, Any]]]
2182-
] = {}
2158+
try:
2159+
from superset.custom_database_errors import CUSTOM_DATABASE_ERRORS
2160+
except ImportError:
2161+
CUSTOM_DATABASE_ERRORS = {}
21832162

21842163

21852164
# -------------------------------------------------------------------

superset/custom_database_errors.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import re
19+
from typing import Any
20+
21+
from superset.errors import SupersetErrorType
22+
23+
# CUSTOM_DATABASE_ERRORS: Configure custom error messages for database exceptions.
24+
# Transform raw database errors into user-friendly messages with optional documentation
25+
# links using custom_doc_links. Set show_issue_info=False to hide default error codes.
26+
# Example:
27+
# CUSTOM_DATABASE_ERRORS = {
28+
# "trino": {
29+
# re.compile(r'message="(?P<message>[^"]*)"'): (
30+
# __(
31+
# 'Unexpected error: "%(message)s"'
32+
# ),
33+
# SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
34+
# {
35+
# "custom_doc_links": [
36+
# {
37+
# "url": "https://example.com/docs/1",
38+
# "label": "Check documentation"
39+
# },
40+
# ],
41+
# "show_issue_info": False,
42+
# }
43+
# )
44+
# }
45+
# }
46+
47+
CUSTOM_DATABASE_ERRORS: dict[
48+
str, dict[re.Pattern[str], tuple[str, SupersetErrorType, dict[str, Any]]]
49+
] = {}

0 commit comments

Comments
 (0)