EnxDev commented on code in PR #43232:
URL: https://github.com/apache/superset/pull/43232#discussion_r4142903261
##########
superset/commands/chart/importers/v1/__init__.py:
##########
@@ -89,10 +133,21 @@ def _import(
dataset = import_dataset(config, overwrite=False)
datasets[str(dataset.uuid)] = dataset
+ # import annotation layers before charts so UUID→ID maps are ready
+ annotation_layer_ids: dict[str, int] = {}
+ for file_name, config in configs.items():
+ if file_name.startswith("annotation_layers/"):
+ layer = import_annotation_layer(config, overwrite=overwrite)
Review Comment:
This landed in 9da7ec0. 87e98f9 then moves the check after the existence
lookup (see the later thread on `annotation_layer/importers/v1/utils.py`), so
it only applies when a layer would be created or overwritten.
##########
superset/commands/chart/importers/v1/__init__.py:
##########
@@ -59,11 +94,18 @@ def _import(
contents: dict[str, Any] | None = None,
) -> None:
contents = {} if contents is None else contents
- # discover datasets associated with charts
+ # discover datasets and referenced chart UUIDs from chart configs
dataset_uuids: set[str] = set()
+ referenced_chart_uuids: set[str] = set()
for file_name, config in configs.items():
if file_name.startswith("charts/"):
dataset_uuids.add(config["dataset_uuid"])
+ for annotation in config.get("params",
{}).get("annotation_layers", []):
+ if annotation.get("sourceType") in (
+ "table",
+ "line",
+ ) and isinstance(annotation.get("value"), str):
+ referenced_chart_uuids.add(annotation["value"])
Review Comment:
Fixed in 87e98f9. The importer now sorts every chart using
`get_chart_annotation_dependencies`, which reads params and query_context.
##########
superset/migrations/versions/2026-08-11_18-38_884a2115ebd3_add_uuid_to_annotation_layer_and_annotation.py:
##########
@@ -0,0 +1,120 @@
+# 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: 2d6ad72e4af6
+Create Date: 2026-08-11 18:38:15.412396
+
+"""
+
+from uuid import uuid4
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.exc import OperationalError
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy_utils import UUIDType
+
+from superset import db
+from superset.migrations.shared.utils import assign_uuids
+
+# revision identifiers, used by Alembic.
+revision = "884a2115ebd3"
+down_revision = "2d6ad72e4af6"
+
+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"
+
+
+def upgrade() -> None:
+ bind = op.get_bind()
+ session = db.Session(bind=bind)
+
+ try:
+ with op.batch_alter_table("annotation_layer") as batch_op:
+ batch_op.add_column(
+ sa.Column(
+ "uuid", UUIDType(binary=True), primary_key=False,
default=uuid4
+ )
+ )
+ except OperationalError:
+ pass
+
+ assign_uuids(AnnotationLayer, session)
Review Comment:
Fixed in 87e98f9. `assign_uuids` now calls `uuid4()`, and the migration uses
the helper. Checked on SQLite with existing rows.
--
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]