mikebridge commented on code in PR #39977:
URL: https://github.com/apache/superset/pull/39977#discussion_r3220592169


##########
superset/models/helpers.py:
##########
@@ -654,7 +655,94 @@ def created_on_humanized(self) -> str:
 
     @renders("changed_on")
     def modified(self) -> Markup:
-        return Markup(f'<span 
class="no-wrap">{self.changed_on_humanized}</span>')
+        return Markup(f'<span 
class="no-wrap">{self.changed_on_humanized}</span>')  # noqa: S704
+
+
+SKIP_VISIBILITY_FILTER = "skip_visibility_filter"
+
+
+class SoftDeleteMixin:
+    """Mixin that adds soft-delete support to a SQLAlchemy model.
+
+    Adds a nullable ``deleted_at`` column. When set, the row is treated as
+    deleted and excluded from standard ORM queries via a global
+    ``do_orm_execute`` listener registered at app init.
+
+    Delete commands should call ``soft_delete()`` to mark the object as
+    deleted.  Use ``BaseDAO.delete()`` (which calls ``session.delete()``)
+    for permanent hard deletion.
+
+    See also: ``_add_soft_delete_filter`` (the listener function) and
+    ``SKIP_VISIBILITY_FILTER`` (the execution-option key used to opt out
+    of the filter in restore commands and admin tooling).
+    """
+
+    deleted_at = sa.Column(sa.DateTime, nullable=True, index=True)
+
+    @hybrid_property
+    def is_deleted(self) -> bool:
+        return self.deleted_at is not None
+
+    @is_deleted.expression  # type: ignore
+    def is_deleted(cls) -> ColumnElement:  # noqa: N805
+        return cls.deleted_at.is_not(None)
+
+    @classmethod
+    def not_deleted(cls) -> ColumnElement:
+        """Filter clause for active (non-deleted) rows."""
+        return cls.deleted_at.is_(None)
+
+    def soft_delete(self) -> None:
+        """Mark this object as soft-deleted."""
+        # Naive datetime, mirroring AuditMixinNullable.changed_on. PR #33693
+        # reverted a UTC migration on the audit columns; if/when those move
+        # to UTC-aware, this assignment should follow.
+        self.deleted_at = datetime.now()

Review Comment:
   Thanks for flagging — declining this one.
   
   Four reasons the naive `datetime.now()` is deliberate here:
   
   1. **Project precedent.** `AuditMixinNullable.changed_on` and `.created_on` 
use naive `datetime.now()`. [PR 
#33693](https://github.com/apache/superset/pull/33693) explicitly reverted a 
UTC migration on those audit columns. `deleted_at` is semantically an audit 
column and should match the convention; diverging would produce a model with 
mixed-TZ columns.
   
   2. **Schema mismatch.** The `deleted_at` column ships as `DateTime`, not 
`DateTime(timezone=True)`. Storing a TZ-aware Python value into a TZ-naive 
Postgres/MySQL column silently strips the timezone on insert, so the suggestion 
would not actually achieve TZ-awareness end-to-end — it would just introduce a 
representation gap between Python and the database.
   
   3. **`pytz.utc` is the wrong import even hypothetically.** Python 3.9+ has 
`datetime.timezone.utc` built-in and `zoneinfo` is the modern stdlib path; 
`pytz` is being phased out. If Superset ever moves to TZ-aware datetimes, it 
won't be via `pytz`.
   
   4. **The PR already documents this.** The inline comment on the 
`soft_delete()` method cites PR #33693 and explicitly notes that `deleted_at` 
should follow if/when the audit columns move to UTC-aware. The bot didn't have 
visibility into that comment.
   
   Resolving as not-applicable.



-- 
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]

Reply via email to