bito-code-review[bot] commented on code in PR #34091:
URL: https://github.com/apache/superset/pull/34091#discussion_r2818384767
##########
tests/unit_tests/db_engine_specs/test_clickhouse.py:
##########
@@ -229,6 +229,33 @@ def test_connect_make_label_compatible(column_name: str,
expected_result: str) -
assert label == expected_result
[email protected](
+ "extra,column_name,expected_result",
+ [
+ # Default behavior (mutate labels)
+ (None, "time", "time_07cc69"),
+ ({}, "time", "time_07cc69"),
+ # Explicitly enable
+ ({"mutate_label_name": True}, "time", "time_07cc69"),
+ # Disabled (no mutation)
+ ({"mutate_label_name": False}, "time", "time"),
+ ({"mutate_label_name": False}, "count", "count"),
+ ],
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incorrect test expectations</b></div>
<div id="fix">
The test expects MD5-based hash suffixes ('time_07cc69'), but the code now
uses SHA-256 by default, producing 'time_336074'. Update all expected results
to match SHA-256 hashes to prevent test failures.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
# Default behavior (mutate labels)
(None, "time", "time_336074"),
({}, "time", "time_336074"),
# Explicitly enable
({"mutate_label_name": True}, "time", "time_336074"),
# Disabled (no mutation)
({"mutate_label_name": False}, "time", "time"),
({"mutate_label_name": False}, "count", "count"),
({"mutate_label_name": True}, "count", "count_6c3549"),
],
````
</div>
</details>
</div>
<small><i>Code Review Run #7382ba</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
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:
<div>
<div id="suggestion">
<div id="issue"><b>Overly broad exception handling in try-except</b></div>
<div id="fix">
Replace the broad `Exception` catch with a more specific exception type.
Consider catching `(KeyError, ValueError, TypeError)` or other specific
exceptions that `database.get_extra()` might raise.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
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."
````
</div>
</details>
</div>
<small><i>Code Review Run #7382ba</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]