You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2026/09/18 07:58:17 UTC

(superset) 01/01: fix(mypy): narrow nullable UUID/description reads in versioning tests

This is an automated email from the ASF dual-hosted git repository.

sadpandajoe pushed a commit to branch ultraset-master-health-versioning-uuid
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 6afb5877568426043a33531c517bea9719cc131c
Author: Joe Li <47...@users.noreply.github.com>
AuthorDate: Fri Sep 18 07:57:56 2026 +0000

    fix(mypy): narrow nullable UUID/description reads in versioning tests
    
    tests/integration_tests/versioning/{conditional_token_lock,
    restore_fails_closed,creation_row,activity_write_after_read}_tests.py
    read nullable UUIDMixin.uuid (and one BaseDatasource.description)
    Column attributes and pass them unnarrowed into strictly-typed
    UUID/str parameters (get_activity, derive_version_uuid,
    restore_version, VersionDAO.current_live_transaction_id[_locked]),
    tripping 23 mypy errors on the nightly full-repo pre-commit run.
    Apply the same assert-narrowing idiom already used elsewhere in this
    suite (PR #42654, commit 120b4420b9) at each read site.
---
 .../versioning/activity_write_after_read_tests.py  |  5 +++-
 .../versioning/conditional_token_lock_tests.py     | 16 ++++++----
 .../versioning/creation_row_tests.py               | 35 ++++++++++++++++------
 .../versioning/restore_fails_closed_tests.py       | 30 ++++++++++++++-----
 4 files changed, 63 insertions(+), 23 deletions(-)

diff --git a/tests/integration_tests/versioning/activity_write_after_read_tests.py b/tests/integration_tests/versioning/activity_write_after_read_tests.py
index c230e675f2d..b621c946084 100644
--- a/tests/integration_tests/versioning/activity_write_after_read_tests.py
+++ b/tests/integration_tests/versioning/activity_write_after_read_tests.py
@@ -24,6 +24,7 @@ activity read being the production shape."""
 from __future__ import annotations
 
 from typing import Any
+from uuid import UUID
 
 from flask_appbuilder.security.sqla.models import User
 from sqlalchemy import event
@@ -67,6 +68,8 @@ class TestActivityReadThenWrite(SupersetTestCase):
         )
         db.session.add(slc)
         db.session.commit()
+        slc_uuid: UUID | None = slc.uuid
+        assert slc_uuid is not None
         try:
             # The read that used to poison the connection. The entity has
             # history (its own INSERT), so the streaming fetch executes.
@@ -92,7 +95,7 @@ class TestActivityReadThenWrite(SupersetTestCase):
             event.listen(db.engine, "before_cursor_execute", observe_change_select)
             try:
                 with override_user(_admin_user()):
-                    records, _, _ = get_activity(Slice, slc.uuid, resolved_entity=slc)
+                    records, _, _ = get_activity(Slice, slc_uuid, resolved_entity=slc)
             finally:
                 event.remove(db.engine, "before_cursor_execute", observe_change_select)
             assert records is not None
diff --git a/tests/integration_tests/versioning/conditional_token_lock_tests.py b/tests/integration_tests/versioning/conditional_token_lock_tests.py
index b91f67bd2bf..9a9161c9fec 100644
--- a/tests/integration_tests/versioning/conditional_token_lock_tests.py
+++ b/tests/integration_tests/versioning/conditional_token_lock_tests.py
@@ -149,12 +149,14 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
         chart: Slice
         original: str | None
         chart, original = self._versioned_chart()
+        chart_uuid: UUID | None = chart.uuid
+        assert chart_uuid is not None
         try:
             plain: int | None = VersionDAO.current_live_transaction_id(
-                Slice, chart.id, chart.uuid
+                Slice, chart.id, chart_uuid
             )
             locked: int | None = VersionDAO.current_live_transaction_id_locked(
-                Slice, chart.id, chart.uuid
+                Slice, chart.id, chart_uuid
             )
             assert plain is not None
             assert locked == plain
@@ -179,6 +181,8 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
         chart: Slice
         original: str | None
         chart, original = self._versioned_chart()
+        chart_uuid: UUID | None = chart.uuid
+        assert chart_uuid is not None
         try:
             db.session.execute(
                 sa.text("DELETE FROM slices_version WHERE id = :id"),
@@ -187,7 +191,7 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
             db.session.commit()
 
             locked: int | None = VersionDAO.current_live_transaction_id_locked(
-                Slice, chart.id, chart.uuid
+                Slice, chart.id, chart_uuid
             )
             assert locked is None
 
@@ -238,7 +242,8 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
         original: str | None
         chart, original = self._versioned_chart()
         chart_id: int = chart.id
-        chart_uuid: UUID = chart.uuid
+        chart_uuid: UUID | None = chart.uuid
+        assert chart_uuid is not None
         try:
             self._force_repeatable_read()
             # Opening the read view: this first consistent read is what
@@ -302,7 +307,8 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
         original: str | None
         chart, original = self._versioned_chart()
         chart_id: int = chart.id
-        chart_uuid: UUID = chart.uuid
+        chart_uuid: UUID | None = chart.uuid
+        assert chart_uuid is not None
         ver_tbl: sa.Table = version_class(Slice).__table__
         try:
             template: sa.RowMapping | None = (
diff --git a/tests/integration_tests/versioning/creation_row_tests.py b/tests/integration_tests/versioning/creation_row_tests.py
index d0fd062fb6c..a2da2a4c200 100644
--- a/tests/integration_tests/versioning/creation_row_tests.py
+++ b/tests/integration_tests/versioning/creation_row_tests.py
@@ -22,6 +22,7 @@ imported)."""
 from __future__ import annotations
 
 from typing import Any
+from uuid import UUID
 
 import sqlalchemy as sa
 from sqlalchemy_continuum import version_class, versioning_manager
@@ -141,7 +142,9 @@ class TestActivityCreationRow(SupersetTestCase):
                 for record in records
             )
             assert all(record["action_kind"] is None for record in records)
-            records, _, _ = get_activity(Slice, created.uuid, resolved_entity=created)
+            created_uuid: UUID | None = created.uuid
+            assert created_uuid is not None
+            records, _, _ = get_activity(Slice, created_uuid, resolved_entity=created)
             assert _creation_records(records)[0]["creation_kind"] == "created"
         finally:
             db.session.rollback()
@@ -152,6 +155,8 @@ class TestActivityCreationRow(SupersetTestCase):
     def test_unstamped_historical_creation_stays_unknown(self) -> None:
         """New writer provenance must not relabel existing unstamped history."""
         slc: Slice = self._make_chart("sc120488_unstamped")
+        slc_uuid: UUID | None = slc.uuid
+        assert slc_uuid is not None
         shadow: sa.Table = version_class(Slice).__table__
         transactions: sa.Table = versioning_manager.transaction_cls.__table__
         try:
@@ -166,7 +171,7 @@ class TestActivityCreationRow(SupersetTestCase):
             )
             db.session.commit()
             records: list[dict[str, Any]]
-            records, _, _ = get_activity(Slice, slc.uuid, resolved_entity=slc)
+            records, _, _ = get_activity(Slice, slc_uuid, resolved_entity=slc)
             assert _creation_records(records)[0]["creation_kind"] == "unknown"
         finally:
             self._cleanup(slc)
@@ -185,12 +190,14 @@ class TestActivityCreationRow(SupersetTestCase):
 
     def test_new_chart_has_one_created_origin_row(self) -> None:
         slc: Slice = self._make_chart("sc120488_new_chart")
+        slc_uuid: UUID | None = slc.uuid
+        assert slc_uuid is not None
         records: list[dict[str, Any]]
         count: int
         truncated: bool
         try:
             records, count, truncated = get_activity(
-                Slice, slc.uuid, resolved_entity=slc
+                Slice, slc_uuid, resolved_entity=slc
             )
             assert not truncated
             creations: list[dict[str, Any]] = _creation_records(records)
@@ -202,7 +209,7 @@ class TestActivityCreationRow(SupersetTestCase):
             # Previewable/restorable: the version_uuid is the one the
             # /versions/ family resolves for the creation transaction.
             assert creation["version_uuid"] == str(
-                derive_version_uuid(slc.uuid, creation["transaction_id"])
+                derive_version_uuid(slc_uuid, creation["transaction_id"])
             )
             # The row is the OLDEST entry and the count includes it.
             assert records[-1] is creation
@@ -214,10 +221,12 @@ class TestActivityCreationRow(SupersetTestCase):
         dash: Dashboard = Dashboard(dashboard_title="sc120488_new_dash", slug=None)
         db.session.add(dash)
         db.session.commit()
+        dash_uuid: UUID | None = dash.uuid
+        assert dash_uuid is not None
         records: list[dict[str, Any]]
         count: int
         try:
-            records, count, _ = get_activity(Dashboard, dash.uuid, resolved_entity=dash)
+            records, count, _ = get_activity(Dashboard, dash_uuid, resolved_entity=dash)
             creations: list[dict[str, Any]] = _creation_records(records)
             assert len(creations) == 1
             assert creations[0]["creation_kind"] == "created"
@@ -230,6 +239,8 @@ class TestActivityCreationRow(SupersetTestCase):
         pre_tracking: its op=0 transaction carries the writer's
         action_kind='baseline' stamp."""
         slc: Slice = self._make_chart("sc120488_pre_tracking")
+        slc_uuid: UUID | None = slc.uuid
+        assert slc_uuid is not None
         records: list[dict[str, Any]]
         try:
             # Simulate an entity that predates versioning: no shadow rows.
@@ -244,7 +255,7 @@ class TestActivityCreationRow(SupersetTestCase):
             from superset.utils.core import override_user
 
             with override_user(_admin_user()):
-                records, _, _ = get_activity(Slice, slc.uuid, resolved_entity=slc)
+                records, _, _ = get_activity(Slice, slc_uuid, resolved_entity=slc)
             creations: list[dict[str, Any]] = _creation_records(records)
             assert len(creations) == 1
             assert creations[0]["creation_kind"] == "pre_tracking"
@@ -259,9 +270,11 @@ class TestActivityCreationRow(SupersetTestCase):
         command's stamp) classifies as imported."""
         db.session.info[ACTION_KIND_KEY] = ACTION_KIND_IMPORT
         slc: Slice = self._make_chart("sc120488_imported")
+        slc_uuid: UUID | None = slc.uuid
+        assert slc_uuid is not None
         records: list[dict[str, Any]]
         try:
-            records, _, _ = get_activity(Slice, slc.uuid, resolved_entity=slc)
+            records, _, _ = get_activity(Slice, slc_uuid, resolved_entity=slc)
             creations: list[dict[str, Any]] = _creation_records(records)
             assert len(creations) == 1
             assert creations[0]["creation_kind"] == "imported"
@@ -272,6 +285,8 @@ class TestActivityCreationRow(SupersetTestCase):
         """Retention pruned the op=0 row (sc-115615 baseline expiry): no
         synthetic row — the timeline just starts at the oldest survivor."""
         slc: Slice = self._make_chart("sc120488_pruned")
+        slc_uuid: UUID | None = slc.uuid
+        assert slc_uuid is not None
         records: list[dict[str, Any]]
         count: int
         try:
@@ -289,7 +304,7 @@ class TestActivityCreationRow(SupersetTestCase):
             from superset.utils.core import override_user
 
             with override_user(_admin_user()):
-                records, count, _ = get_activity(Slice, slc.uuid, resolved_entity=slc)
+                records, count, _ = get_activity(Slice, slc_uuid, resolved_entity=slc)
             assert not _creation_records(records)
             assert count == len(records)
         finally:
@@ -297,10 +312,12 @@ class TestActivityCreationRow(SupersetTestCase):
 
     def test_include_related_never_synthesizes(self) -> None:
         slc: Slice = self._make_chart("sc120488_related_only")
+        slc_uuid: UUID | None = slc.uuid
+        assert slc_uuid is not None
         records: list[dict[str, Any]]
         try:
             records, _, _ = get_activity(
-                Slice, slc.uuid, resolved_entity=slc, include="related"
+                Slice, slc_uuid, resolved_entity=slc, include="related"
             )
             assert not _creation_records(records)
         finally:
diff --git a/tests/integration_tests/versioning/restore_fails_closed_tests.py b/tests/integration_tests/versioning/restore_fails_closed_tests.py
index b7c45dabe06..292fc36abe4 100644
--- a/tests/integration_tests/versioning/restore_fails_closed_tests.py
+++ b/tests/integration_tests/versioning/restore_fails_closed_tests.py
@@ -146,7 +146,8 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         dataset, column, target_tx, _ = self._two_version_dataset()
         edited_description: str | None = column.description
         column_count: int = len(dataset.columns)
-        dataset_uuid: UUID = dataset.uuid
+        dataset_uuid: UUID | None = dataset.uuid
+        assert dataset_uuid is not None
         column_id: int = column.id
 
         closed: list[Any] = _closed_column_shadow_rows(column.id)
@@ -372,12 +373,16 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         before: str
         dataset, column, target_tx, before = self._two_version_dataset()
         assert column.description != before
-        parent_target_description: str = dataset.description.removesuffix("_v2")
+        dataset_description: str | None = dataset.description
+        assert dataset_description is not None
+        parent_target_description: str = dataset_description.removesuffix("_v2")
+        dataset_uuid: UUID | None = dataset.uuid
+        assert dataset_uuid is not None
         assert _delete_column_shadow_rows(column.id, closed_only=True) >= 1
 
         with patch("superset.versioning.restore._verify_child_history_complete"):
             result: RestoreResult | None = restore_version(
-                SqlaTable, dataset.uuid, target_tx, entity=dataset
+                SqlaTable, dataset_uuid, target_tx, entity=dataset
             )
 
         assert result is not None
@@ -394,9 +399,11 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         target_tx: int
         before: str
         dataset, column, target_tx, before = self._two_version_dataset()
+        dataset_uuid: UUID | None = dataset.uuid
+        assert dataset_uuid is not None
 
         result: RestoreResult | None = restore_version(
-            SqlaTable, dataset.uuid, target_tx, entity=dataset
+            SqlaTable, dataset_uuid, target_tx, entity=dataset
         )
 
         assert result is not None
@@ -422,6 +429,8 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         dataset, column, target_tx, _ = self._two_version_dataset()
         edited_description: str | None = column.description
         parent_description: str | None = dataset.description
+        dataset_uuid: UUID | None = dataset.uuid
+        assert dataset_uuid is not None
         assert _delete_column_shadow_rows(column.id, closed_only=True) >= 1
 
         with patch(
@@ -429,7 +438,7 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
             side_effect=AssertionError("write phase entered before refusal"),
         ):
             with pytest.raises(PrunedChildHistoryError):
-                restore_version(SqlaTable, dataset.uuid, target_tx, entity=dataset)
+                restore_version(SqlaTable, dataset_uuid, target_tx, entity=dataset)
 
         # No rollback yet: ORM pending state must already be clean.
         assert not db.session.new
@@ -465,7 +474,8 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         dataset: SqlaTable
         target_tx: int
         dataset, _, target_tx, _ = self._two_version_dataset()
-        dataset_uuid: UUID = dataset.uuid
+        dataset_uuid: UUID | None = dataset.uuid
+        assert dataset_uuid is not None
         versions: list[dict[str, Any]] | None = list_versions(
             SqlaTable, dataset_uuid, entity=dataset
         )
@@ -532,8 +542,10 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         # Prune the ENTIRE chain (insert row, closed rows, delete row).
         assert _delete_column_shadow_rows(added_id, closed_only=False) >= 1
 
+        dataset_uuid: UUID | None = dataset.uuid
+        assert dataset_uuid is not None
         result: RestoreResult | None = restore_version(
-            SqlaTable, dataset.uuid, target_tx, entity=dataset
+            SqlaTable, dataset_uuid, target_tx, entity=dataset
         )
 
         assert result is not None
@@ -556,6 +568,8 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         column: TableColumn
         target_tx: int
         dataset, column, target_tx, _ = self._two_version_dataset()
+        dataset_uuid: UUID | None = dataset.uuid
+        assert dataset_uuid is not None
 
         # Remove a column and take a post-delete snapshot point.
         removed_id: int = dataset.columns[-1].id
@@ -612,7 +626,7 @@ class TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
         db.session.commit()
 
         result: RestoreResult | None = restore_version(
-            SqlaTable, dataset.uuid, target_tx, entity=dataset
+            SqlaTable, dataset_uuid, target_tx, entity=dataset
         )
 
         assert result is not None