bito-code-review[bot] commented on code in PR #34091:
URL: https://github.com/apache/superset/pull/34091#discussion_r2818766908
##########
superset/db_engine_specs/clickhouse.py:
##########
@@ -519,15 +519,41 @@ def validate_parameters(
return []
@staticmethod
- def _mutate_label(label: str) -> str:
+ def _mutate_label(label: str, database: Database | None = None) -> str:
"""
- Suffix with the first six characters from the md5 of the label to avoid
- collisions with original column names
+ Conditionally suffix the label with the first six characters from the
md5
+ of the label to avoid collisions with original column names.
+
+ By default, labels are mutated for backward compatibility. To disable
this
+ behavior on a per-database basis, set `mutate_label_name` to `false` in
+ the database's "extra" JSON configuration in the Superset UI:
+
+ {
+ "mutate_label_name": false
+ }
+
+ This is useful when your ClickHouse queries refer to their own aliases
+ within the same SELECT statement.
:param label: Expected expression label
- :return: Conditionally mutated label
+ :param database: Database instance for db-specific label mutation logic
+ :return: Mutated label if mutation is enabled, otherwise the original
label
"""
- return f"{label}_{hash_from_str(label)[:6]}"
+ mutate_label = True
+
+ if database:
+ try:
+ extra = database.get_extra()
+ mutate_label = extra.get("mutate_label_name", True)
+ except Exception: # pylint: disable=broad-except
+ logger.warning(
+ "Error retrieving mutate_label_name setting. Falling back
to "
+ "default behavior of True."
Review Comment:
<!-- Bito Reply -->
The broad exception handling in the suggestion is appropriate for this label
formatting helper, as it prioritizes graceful fallback over potential crashes
from various errors during settings retrieval.
**superset/db_engine_specs/clickhouse.py**
```
if database:
try:
extra = database.get_extra()
mutate_label = extra.get("mutate_label_name", True)
except (KeyError, ValueError, TypeError, AttributeError):
logger.warning(
"Error retrieving mutate_label_name setting. Falling
back to "
"default behavior of True."
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]