EnxDev commented on code in PR #43232:
URL: https://github.com/apache/superset/pull/43232#discussion_r4149481795
##########
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:
Added in 90d7ba9.
##########
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:
Fixed in 90d7ba9. `assign_uuids` still fills a freshly added column in one
go, but when some rows already have a UUID only the empty ones are filled.
Checked on SQLite with a pre-set UUID, which survives the upgrade.
##########
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:
Leaving these as is. The other tests in the module don't annotate their
locals either, and all three are inferred.
##########
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:
Fixed in 90d7ba9. A nested export that writes neither `selected_charts.yaml`
nor `tags.yaml` now skips the walk.
##########
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:
Fixed by the same change in 90d7ba9: the dashboard's nested chart export no
longer walks the sources, so it only happens once per dashboard.
--
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]