bito-code-review[bot] commented on code in PR #43232:
URL: https://github.com/apache/superset/pull/43232#discussion_r4145088092
##########
superset/commands/dashboard/importers/v1/__init__.py:
##########
@@ -119,6 +127,23 @@ def _import(
if config.get("theme_uuid"):
theme_uuids.add(config["theme_uuid"])
+ # discover charts used as annotation sources by those charts, which can
+ # be in the bundle without being in any dashboard layout
+ chart_configs_by_uuid = {
+ str(config["uuid"]): config
+ for file_name, config in configs.items()
+ if file_name.startswith("charts/")
+ }
+ pending_chart_uuids = list(chart_uuids)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing type annotations</b></div>
<div id="fix">
The new locals `chart_configs_by_uuid` and `pending_chart_uuids` lack the
explicit type annotations that sibling declarations in `_import` carry
(`chart_uuids: set[str]`, `dataset_uuids: set[str]`, `theme_uuids: set[str]`),
contrary to the org typing rule for newly introduced locals. Adding `dict[str,
dict[str, Any]]` / `list[str]` keeps the function's annotation style uniform.
</div>
</div>
<small><i>Code Review Run #3ff57d</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/commands/dashboard/export.py:
##########
@@ -441,7 +441,10 @@ def _export(
command.enable_tag_export()
if feature_flag_manager.is_feature_enabled("TAGGING_SYSTEM"):
yield from ExportTagsCommand(
- dashboard_ids=dashboard_ids, chart_ids=chart_ids
+ dashboard_ids=dashboard_ids,
+
chart_ids=ExportChartsCommand.chart_ids_with_annotation_sources(
+ model.slices
+ ),
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Redundant annotation-source scan</b></div>
<div id="fix">
`chart_ids_with_annotation_sources(model.slices)` is recomputed here, but
`command.run(seen=seen)` at line 439 already computes the same value internally
(chart/export.py:198) before the `_include_tags` gate. This doubles the
`ChartDAO.find_by_ids` queries and params/query_context JSON parsing on every
dashboard export with TAGGING_SYSTEM. Reuse the value computed in
`ExportChartsCommand.run()`.
</div>
</div>
<small><i>Code Review Run #3ff57d</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/migrations/versions/2026-08-17_18-38_884a2115ebd3_add_uuid_to_annotation_layer_and_annotation.py:
##########
@@ -0,0 +1,100 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""add_uuid_to_annotation_layer_and_annotation
+
+Revision ID: 884a2115ebd3
+Revises: 95d8a99c822e
+Create Date: 2026-08-11 18:38:15.412396
+
+"""
+
+from uuid import uuid4
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy_utils import UUIDType
+
+from superset import db
+from superset.migrations.shared.utils import (
+ add_columns,
+ assign_uuids,
+ drop_columns,
+ has_table,
+)
+
+# revision identifiers, used by Alembic.
+revision = "884a2115ebd3"
+down_revision = "95d8a99c822e"
+
+Base = declarative_base()
+
+
+class ImportMixin:
+ id = sa.Column(sa.Integer, primary_key=True)
+ uuid = sa.Column(UUIDType(binary=True), primary_key=False, default=uuid4)
+
+
+class AnnotationLayer(ImportMixin, Base):
+ __tablename__ = "annotation_layer"
+
+
+class Annotation(ImportMixin, Base):
+ __tablename__ = "annotation"
+
+
+MODELS = (AnnotationLayer, Annotation)
+
+
+def _has_unique_constraint(table_name: str, constraint_name: str) -> bool:
+ inspector = sa.inspect(op.get_bind())
+ return any(
+ constraint["name"] == constraint_name
+ for constraint in inspector.get_unique_constraints(table_name)
+ )
+
+
+def upgrade() -> None:
+ session = db.Session(bind=op.get_bind())
+
+ for model in MODELS:
+ table_name = model.__tablename__
+ if not has_table(table_name):
+ continue
+ add_columns(
+ table_name,
+ sa.Column("uuid", UUIDType(binary=True), primary_key=False,
default=uuid4),
+ )
+ if session.query(model).filter(model.uuid.is_(None)).count():
+ assign_uuids(model, session)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Backfill overwrites existing UUIDs</b></div>
<div id="fix">
The deleted `_assign_missing_uuids` backfilled only rows with `uuid IS
NULL`; the replacement delegates to shared `assign_uuids`, whose MySQL/PG path
runs `UPDATE <table> SET uuid = <sql>` with no WHERE clause and whose fallback
paginates over `session.query(model)` (all rows). If a first run fails partway
(paginated_update commits per batch), a re-run silently regenerates UUIDs for
rows that already had them, breaking external references to those identifiers.
Consider a NULL-only backfill.
</div>
</div>
<small><i>Code Review Run #3ff57d</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
##########
tests/unit_tests/charts/commands/importers/v1/utils_test.py:
##########
@@ -281,3 +285,24 @@ def test_migrate_chart_table_migrates_when_flag_enabled(
assert new_config["viz_type"] == "ag-grid-table"
assert json.loads(new_config["params"])["viz_type"] == "ag-grid-table"
+
+
+def test_get_dependency_chart_uuids_uses_selection_file() -> None:
+ """Charts missing from the selection file are dependencies."""
+ configs = [{"uuid": "a"}, {"uuid": "b"}, {"uuid": "c"}]
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing test local type hints</b></div>
<div id="fix">
The new tests bind `configs`, `contents`, and the loop variable `raw`
without type annotations (lines 292-293, 299-300, 305-307), while the module's
older tests annotate fixtures (`mocker: MockerFixture`). BITO rule 13153
requires explicit annotations for test locals even when inferable; adding
`configs: list[dict[str, str]]`, `contents: dict[str, str]`, `raw: str` keeps
the file consistent.
</div>
</div>
<small><i>Code Review Run #3ff57d</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/commands/chart/export.py:
##########
@@ -100,28 +190,53 @@ def enable_tag_export(cls) -> None:
def run(
self, seen: set[str] | None = None
) -> Iterator[tuple[str, Callable[[], str]]]:
+ is_root = seen is None
yield from super().run(seen=seen)
+ if not self.export_related:
+ return
+
+ chart_ids =
ExportChartsCommand.chart_ids_with_annotation_sources(self._models)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Wasted annotation-source walk</b></div>
<div id="fix">
`chart_ids_with_annotation_sources(self._models)` is now computed
unconditionally, but its result is only consumed by the `selected_charts.yaml`
yield (requires `is_root`) and the tags yield (requires `_include_tags` and the
flag). On the dashboard export path (`ExportChartsCommand` at
`dashboard/export.py:435` calls `disable_tag_export()` then `run(seen=seen)`),
the recursive JSON-parse/DB walk runs and the result is discarded. Gate the
computation on the same conditions that consume it.
</div>
</div>
<small><i>Code Review Run #3ff57d</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]