This is an automated email from the ASF dual-hosted git repository.
sadpandajoe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new f5d663c480d fix(versioning): narrow nullable uuid/description reads
flagged by mypy in versioning tests (#44424)
f5d663c480d is described below
commit f5d663c480d25cccb0155a2aaef57bab909b4cb7
Author: Konstantin Khlopkov <[email protected]>
AuthorDate: Thu Sep 24 23:26:30 2026 +0300
fix(versioning): narrow nullable uuid/description reads flagged by mypy in
versioning tests (#44424)
---
.../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 | 23 ++++++++++----
4 files changed, 59 insertions(+), 20 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..7a29c2938f5 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
@@ -91,8 +92,10 @@ class TestActivityReadThenWrite(SupersetTestCase):
records: list[dict[str, Any]]
event.listen(db.engine, "before_cursor_execute",
observe_change_select)
try:
+ slc_uuid: UUID = slc.uuid
+ assert slc_uuid is not None
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..af32ac24286 100644
--- a/tests/integration_tests/versioning/conditional_token_lock_tests.py
+++ b/tests/integration_tests/versioning/conditional_token_lock_tests.py
@@ -150,17 +150,19 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
original: str | None
chart, original = self._versioned_chart()
try:
+ chart_uuid: UUID = chart.uuid
+ assert chart_uuid is not None
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
info: EntityVersionInfo = current_entity_version_info(
- Slice, chart.id, chart.uuid, lock_for_stale_check=True
+ Slice, chart.id, chart_uuid, lock_for_stale_check=True
)
assert info.transaction_id == plain
finally:
@@ -180,6 +182,8 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
original: str | None
chart, original = self._versioned_chart()
try:
+ chart_uuid: UUID = chart.uuid
+ assert chart_uuid is not None
db.session.execute(
sa.text("DELETE FROM slices_version WHERE id = :id"),
{"id": chart.id},
@@ -187,12 +191,12 @@ 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
info: EntityVersionInfo = current_entity_version_info(
- Slice, chart.id, chart.uuid, lock_for_stale_check=True
+ Slice, chart.id, chart_uuid, lock_for_stale_check=True
)
assert info.version_uuid is None
assert info.entity_uuid == chart.uuid
@@ -239,6 +243,7 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
chart, original = self._versioned_chart()
chart_id: int = chart.id
chart_uuid: UUID = chart.uuid
+ assert chart_uuid is not None
try:
self._force_repeatable_read()
# Opening the read view: this first consistent read is what
@@ -303,6 +308,7 @@ class TestConditionalTokenLockingRead(SupersetTestCase):
chart, original = self._versioned_chart()
chart_id: int = chart.id
chart_uuid: UUID = 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..8f86b5e18b0 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 = 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()
@@ -165,8 +168,10 @@ class TestActivityCreationRow(SupersetTestCase):
.values(action_kind=None)
)
db.session.commit()
+ slc_uuid: UUID = slc.uuid
+ assert slc_uuid is not None
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)
@@ -189,8 +194,10 @@ class TestActivityCreationRow(SupersetTestCase):
count: int
truncated: bool
try:
+ slc_uuid: UUID = slc.uuid
+ assert slc_uuid is not None
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
@@ -217,7 +224,9 @@ class TestActivityCreationRow(SupersetTestCase):
records: list[dict[str, Any]]
count: int
try:
- records, count, _ = get_activity(Dashboard, dash.uuid,
resolved_entity=dash)
+ dash_uuid: UUID = dash.uuid
+ assert dash_uuid is not None
+ 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"
@@ -243,8 +252,10 @@ class TestActivityCreationRow(SupersetTestCase):
# pylint: disable=import-outside-toplevel
from superset.utils.core import override_user
+ slc_uuid: UUID = slc.uuid
+ assert slc_uuid is not None
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"
@@ -261,7 +272,9 @@ class TestActivityCreationRow(SupersetTestCase):
slc: Slice = self._make_chart("sc120488_imported")
records: list[dict[str, Any]]
try:
- records, _, _ = get_activity(Slice, slc.uuid, resolved_entity=slc)
+ slc_uuid: UUID = slc.uuid
+ assert slc_uuid is not None
+ 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"
@@ -288,8 +301,10 @@ class TestActivityCreationRow(SupersetTestCase):
# pylint: disable=import-outside-toplevel
from superset.utils.core import override_user
+ slc_uuid: UUID = slc.uuid
+ assert slc_uuid is not None
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:
@@ -299,8 +314,10 @@ class TestActivityCreationRow(SupersetTestCase):
slc: Slice = self._make_chart("sc120488_related_only")
records: list[dict[str, Any]]
try:
+ slc_uuid: UUID = slc.uuid
+ assert slc_uuid is not None
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..5148ed7d109 100644
--- a/tests/integration_tests/versioning/restore_fails_closed_tests.py
+++ b/tests/integration_tests/versioning/restore_fails_closed_tests.py
@@ -147,6 +147,7 @@ class
TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
edited_description: str | None = column.description
column_count: int = len(dataset.columns)
dataset_uuid: UUID = 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,15 @@ class
TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
before: str
dataset, column, target_tx, before = self._two_version_dataset()
assert column.description != before
+ assert dataset.uuid is not None
+ dataset_uuid: UUID = dataset.uuid
+ assert dataset.description is not None
parent_target_description: str =
dataset.description.removesuffix("_v2")
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
@@ -395,8 +399,10 @@ class
TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
before: str
dataset, column, target_tx, before = self._two_version_dataset()
+ dataset_uuid: UUID = 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 +428,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 = dataset.uuid
+ assert dataset_uuid is not None
assert _delete_column_shadow_rows(column.id, closed_only=True) >= 1
with patch(
@@ -429,7 +437,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
@@ -466,6 +474,7 @@ class
TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
target_tx: int
dataset, _, target_tx, _ = self._two_version_dataset()
dataset_uuid: UUID = dataset.uuid
+ assert dataset_uuid is not None
versions: list[dict[str, Any]] | None = list_versions(
SqlaTable, dataset_uuid, entity=dataset
)
@@ -532,8 +541,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 = 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
@@ -611,8 +622,10 @@ class
TestRestoreFailsClosedOnPrunedChildHistory(SupersetTestCase):
)
db.session.commit()
+ dataset_uuid: UUID = 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