You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2024/09/26 01:02:09 UTC

(superset) 01/02: feat: add and use UUIDMixin for most models

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

maximebeauchemin pushed a commit to branch uuid_mixin
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b7c51ce91093a7e36a265051d4bad1668489cfad
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Wed Sep 25 17:58:18 2024 -0700

    feat: add and use UUIDMixin for most models
---
 superset/models/core.py    | 6 +++---
 superset/models/helpers.py | 8 +++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/superset/models/core.py b/superset/models/core.py
index 5d3a6ea74d..32f9f734ae 100755
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -71,7 +71,7 @@ from superset.extensions import (
     security_manager,
     ssh_manager_factory,
 )
-from superset.models.helpers import AuditMixinNullable, ImportExportMixin
+from superset.models.helpers import AuditMixinNullable, ImportExportMixin, UUIDMixin
 from superset.result_set import SupersetResultSet
 from superset.sql_parse import Table
 from superset.superset_typing import OAuth2ClientConfig, ResultSetColumnType
@@ -102,7 +102,7 @@ class KeyValue(Model):  # pylint: disable=too-few-public-methods
     value = Column(utils.MediumText(), nullable=False)
 
 
-class CssTemplate(Model, AuditMixinNullable):
+class CssTemplate(Model, AuditMixinNullable, UUIDMixin):
     """CSS templates for dashboards"""
 
     __tablename__ = "css_templates"
@@ -1174,7 +1174,7 @@ class FavStarClassName(StrEnum):
     DASHBOARD = "Dashboard"
 
 
-class FavStar(Model):  # pylint: disable=too-few-public-methods
+class FavStar(Model, UUIDMixin):
     __tablename__ = "favstar"
 
     id = Column(Integer, primary_key=True)
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index 80e66f5027..eb01de3c49 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -167,11 +167,17 @@ def convert_uuids(obj: Any) -> Any:
     return obj
 
 
-class ImportExportMixin:
+class UUIDMixin:  # pylint: disable=too-few-public-methods
     uuid = sa.Column(
         UUIDType(binary=True), primary_key=False, unique=True, default=uuid.uuid4
     )
 
+    @property
+    def short_uuid(self) -> str:
+        return str(self.uuid)[:8]
+
+
+class ImportExportMixin(UUIDMixin):
     export_parent: Optional[str] = None
     # The name of the attribute
     # with the SQL Alchemy back reference