codeant-ai-for-open-source[bot] commented on code in PR #41549:
URL: https://github.com/apache/superset/pull/41549#discussion_r3573672664


##########
superset/commands/deletion_retention/force_purge.py:
##########
@@ -0,0 +1,118 @@
+# 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.
+"""Compliance force-purge of a single entity by UUID.
+
+Immediate, irreversible removal of one entity regardless of the retention
+window or whether it is currently soft-deleted or live. Runs the same cascade
+as the time-based task with ``enforce_window=False`` โ€” identical dependent
+handling with legacy hard-delete semantics: M:N join rows hard-deleted,
+a referencing live chart's loose ``datasource_id`` left dangling (the chart is
+never modified). Idempotent: a UUID that resolves to nothing is a no-op.
+"""
+
+from __future__ import annotations
+
+import logging
+from typing import Any, cast
+
+from superset import db
+from superset.commands.deletion_retention import audit
+from superset.commands.deletion_retention.purge_cascade import (
+    cascade_hard_delete,
+    CascadeResult,
+    dashboard_slice_count,
+    suspend_version_capture,
+)
+from superset.models.helpers import skip_visibility_filter, SoftDeleteMixin
+
+logger = logging.getLogger(__name__)

Review Comment:
   **Suggestion:** Add an explicit type annotation for the module logger 
variable. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The rule requires type hints on relevant variables that can be annotated. 
The module-level `logger` is a clearly typed value (`logging.Logger`) but is 
declared without an annotation, so this is a real violation.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aac2d6d32a2d4b2291442118370a6900&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=aac2d6d32a2d4b2291442118370a6900&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/commands/deletion_retention/force_purge.py
   **Line:** 42:42
   **Comment:**
        *Custom Rule: Add an explicit type annotation for the module logger 
variable.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=fdbc55df6942216c834b88fef4d344cf4716c86b24ab3e410c7c3d94af9925ae&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=fdbc55df6942216c834b88fef4d344cf4716c86b24ab3e410c7c3d94af9925ae&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/commands/deletion_retention/audit.py:
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Write-ahead purge audit record.
+
+Every purge โ€” time-based or force โ€” writes an immutable record that
+**survives** the entity it names, on a **dedicated session** outside the
+purge transaction so it neither entangles with the ``DBEventLogger``
+(which shares ``db.session`` and commits mid-request) nor vanishes if the
+purge rolls back. The record is written ``pending`` *before* the purge and
+flipped to ``confirmed`` *after* it commits, so a crash leaves at most a
+``pending`` row, never a missing one. ``pending`` rows are reconciled on the
+next run (the purge is convergent).
+
+The dedicated ``purge_audit_log`` table is content-free (no name or PII; only
+action, actor, UTC time, entity type, UUID, and affected referrers) and is 
never
+removed by the purge cascade.
+"""
+
+from __future__ import annotations
+
+import logging
+from datetime import datetime, timedelta
+from typing import Any, cast
+
+import sqlalchemy as sa
+from sqlalchemy import Column, DateTime, Integer, String, Text
+from sqlalchemy.orm import Session, sessionmaker
+
+from superset import db
+
+logger = logging.getLogger(__name__)
+
+
+def _dedicated_session() -> Session:
+    """A fresh session on its own connection, independent of the request /
+    task ``db.session``. The audit write must commit on its own so it survives
+    a rolled-back or crashed purge."""
+    return sessionmaker(bind=db.engine)()
+
+
+STATUS_PENDING = "pending"
+STATUS_CONFIRMED = "confirmed"
+STATUS_FAILED = "failed"
+STATUS_BLOCKED = "blocked"
+
+_PENDING_STALE_AFTER = timedelta(hours=1)
+
+TRIGGER_RETENTION = "retention"
+TRIGGER_FORCE = "force"
+
+ACTOR_SYSTEM = "system"
+
+
+class PurgeAuditLog(db.Model):
+    """Immutable, content-free record of a purge."""
+
+    __tablename__ = "purge_audit_log"
+
+    id = Column(Integer, primary_key=True)

Review Comment:
   **Suggestion:** Replace the auto-increment integer primary key with a 
UUID-based primary key definition for this new model. [custom_rule]
   
   **Severity Level:** Major โš ๏ธ
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The file adds a new SQLAlchemy model, and its primary key is defined as an 
auto-incrementing integer. This directly violates the rule preferring UUID 
primary keys for new models and public APIs.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .github/copilot-instructions.md (line 51)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c0d2a9add50a470287bfdc27ec55f27c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c0d2a9add50a470287bfdc27ec55f27c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/commands/deletion_retention/audit.py
   **Line:** 73:73
   **Comment:**
        *Custom Rule: Replace the auto-increment integer primary key with a 
UUID-based primary key definition for this new model.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=2c3db310bffd40f74dbd696bab8595ee390ad0472c654eccb4394ba4fea60002&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=2c3db310bffd40f74dbd696bab8595ee390ad0472c654eccb4394ba4fea60002&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/commands/deletion_retention/window.py:
##########
@@ -0,0 +1,63 @@
+# 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.
+"""Resolve the soft-delete retention window."""
+
+from __future__ import annotations
+
+import logging
+
+from flask import current_app
+
+from superset.key_value.shared_entries import get_shared_value
+from superset.key_value.types import SharedKey
+
+logger = logging.getLogger(__name__)
+
+_DEFAULT_RETENTION_DAYS = 30

Review Comment:
   **Suggestion:** Add explicit type annotations for the new module-level 
variables so static typing can validate them. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The new module introduces two annotatable module-level variables without 
type hints: `logger` and `_DEFAULT_RETENTION_DAYS`. This matches the rule 
requiring Python code to include type hints on relevant variables that can be 
annotated.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a28cb011b26f4b9ea2132f7cdc303f5d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a28cb011b26f4b9ea2132f7cdc303f5d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/commands/deletion_retention/window.py
   **Line:** 28:30
   **Comment:**
        *Custom Rule: Add explicit type annotations for the new module-level 
variables so static typing can validate them.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=060419617454041a308017016481b15351fbca4efb9e529c8d3ec87947c3c093&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=060419617454041a308017016481b15351fbca4efb9e529c8d3ec87947c3c093&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/commands/deletion_retention/force_purge.py:
##########
@@ -0,0 +1,118 @@
+# 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.
+"""Compliance force-purge of a single entity by UUID.
+
+Immediate, irreversible removal of one entity regardless of the retention
+window or whether it is currently soft-deleted or live. Runs the same cascade
+as the time-based task with ``enforce_window=False`` โ€” identical dependent
+handling with legacy hard-delete semantics: M:N join rows hard-deleted,
+a referencing live chart's loose ``datasource_id`` left dangling (the chart is
+never modified). Idempotent: a UUID that resolves to nothing is a no-op.
+"""
+
+from __future__ import annotations
+
+import logging
+from typing import Any, cast
+
+from superset import db
+from superset.commands.deletion_retention import audit
+from superset.commands.deletion_retention.purge_cascade import (
+    cascade_hard_delete,
+    CascadeResult,
+    dashboard_slice_count,
+    suspend_version_capture,
+)
+from superset.models.helpers import skip_visibility_filter, SoftDeleteMixin
+
+logger = logging.getLogger(__name__)
+
+
+class ForcePurgeCommand:
+    """Force-purge the entity identified by *uuid*, if any."""
+
+    def __init__(self, uuid: str, actor: str = "operator") -> None:
+        self._uuid = uuid
+        self._actor = actor

Review Comment:
   **Suggestion:** Add explicit type annotations for the instance attributes 
assigned in the initializer. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The rule requires type hints for relevant variables that can be annotated. 
These instance attributes are assigned in `__init__` without annotations, and 
their types are known from the parameters (`str`), so this is a genuine 
violation.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=21e9e7a0075144e6886321089ccf4105&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=21e9e7a0075144e6886321089ccf4105&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/commands/deletion_retention/force_purge.py
   **Line:** 49:50
   **Comment:**
        *Custom Rule: Add explicit type annotations for the instance attributes 
assigned in the initializer.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=f3e2047062a9cb3ecfa1d9eebf30b407dc52599153b296773b0ac6ce7149bfee&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=f3e2047062a9cb3ecfa1d9eebf30b407dc52599153b296773b0ac6ce7149bfee&reaction=dislike'>๐Ÿ‘Ž</a>



##########
tests/unit_tests/tasks/test_deletion_retention.py:
##########
@@ -0,0 +1,131 @@
+# 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.
+"""Unit tests for deletion-retention configuration and window resolution.
+
+The shared value overrides config, an unset value falls back to config, ``0``
+is preserved as the disable value, and malformed shared values use the 
fallback.
+"""
+
+from datetime import datetime
+from typing import Any
+from unittest.mock import patch
+
+import pytest
+from flask.config import Config
+
+
[email protected]
+def app_config(app_context: None) -> Config:
+    from flask import current_app
+
+    current_app.config["SUPERSET_SOFT_DELETE_RETENTION_DAYS"] = 30
+    return current_app.config
+
+
+def _resolve() -> int:
+    from superset.commands.deletion_retention.window import 
resolve_retention_window
+
+    return resolve_retention_window()
+
+
+def test_unset_falls_back_to_config(app_config: Config) -> None:
+    with patch(
+        "superset.commands.deletion_retention.window.get_shared_value",
+        return_value=None,
+    ):
+        assert _resolve() == 30
+
+
+def test_shared_value_overrides_config(app_config: Config) -> None:
+    with patch(
+        "superset.commands.deletion_retention.window.get_shared_value",
+        return_value=7,
+    ):
+        assert _resolve() == 7
+
+
+def test_zero_shared_value_is_preserved_not_coerced(app_config: Config) -> 
None:
+    # `0` is a meaningful "disable"; it must survive (never `or`-coerced to 
30).
+    with patch(
+        "superset.commands.deletion_retention.window.get_shared_value",
+        return_value=0,
+    ):
+        assert _resolve() == 0
+
+
+def test_malformed_shared_value_falls_back(app_config: Config) -> None:
+    for bad in ("oops", -3, True, 1.5):
+        with patch(
+            "superset.commands.deletion_retention.window.get_shared_value",
+            return_value=bad,
+        ):
+            assert _resolve() == 30
+
+
+def test_window_zero_disables_the_task(app_context: None) -> None:
+    # A zero window short-circuits the purge entirely.
+    import superset.tasks.deletion_retention as mod
+
+    with patch.object(mod, "_soft_delete_models") as models:
+        result = mod._purge_impl(0, dry_run=False)
+    assert result == {"skipped": 1}
+    models.assert_not_called()
+
+
+def test_clock_uses_now_not_utcnow() -> None:
+    # The cutoff uses the same clock as the soft-delete substrate's deleted_at.
+    import inspect
+
+    import superset.tasks.deletion_retention as mod
+
+    src = inspect.getsource(mod._purge_impl)
+    assert "datetime.now()" in src
+    assert "datetime.utcnow()" not in src
+
+
+def test_default_config_is_safe() -> None:
+    from superset import config
+
+    assert config.SUPERSET_SOFT_DELETE_RETENTION_DAYS == 30
+    assert config.SUPERSET_SOFT_DELETE_PURGE_DRY_RUN is True
+
+
+def test_default_celery_config_registers_daily_purge() -> None:
+    from superset import config
+
+    assert "superset.tasks.deletion_retention" in config.CeleryConfig.imports
+    entry: dict[str, Any] = config.CeleryConfig.beat_schedule[
+        "deletion_retention.purge_soft_deleted"
+    ]
+    assert entry["task"] == "deletion_retention.purge_soft_deleted"
+
+
+def test_purge_model_counts_only_committed_deletions(app_context: None) -> 
None:
+    import superset.tasks.deletion_retention as mod
+    from superset.commands.deletion_retention.purge_cascade import 
CascadeResult
+    from superset.models.slice import Slice
+
+    lost_race = CascadeResult(
+        purged=False, entity_type="chart", entity_uuid="lost-race"
+    )

Review Comment:
   **Suggestion:** Add an explicit type annotation for this local variable to 
satisfy the rule requiring type hints on relevant variables. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   This new Python local variable is inferable but not annotated, and the rule 
explicitly requires type hints on relevant variables that can be annotated. The 
suggestion matches a real omission in the existing code.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=376dd694445e45a49048cd7a12407096&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=376dd694445e45a49048cd7a12407096&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/tasks/test_deletion_retention.py
   **Line:** 122:124
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this local variable 
to satisfy the rule requiring type hints on relevant variables.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=82d6ada13688b22ecb8ec2dadf5100d429622a18a6798d71a66cbdffdb7288db&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=82d6ada13688b22ecb8ec2dadf5100d429622a18a6798d71a66cbdffdb7288db&reaction=dislike'>๐Ÿ‘Ž</a>



##########
tests/unit_tests/tasks/test_deletion_retention.py:
##########
@@ -0,0 +1,131 @@
+# 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.
+"""Unit tests for deletion-retention configuration and window resolution.
+
+The shared value overrides config, an unset value falls back to config, ``0``
+is preserved as the disable value, and malformed shared values use the 
fallback.
+"""
+
+from datetime import datetime
+from typing import Any
+from unittest.mock import patch
+
+import pytest
+from flask.config import Config
+
+
[email protected]
+def app_config(app_context: None) -> Config:
+    from flask import current_app
+
+    current_app.config["SUPERSET_SOFT_DELETE_RETENTION_DAYS"] = 30
+    return current_app.config
+
+
+def _resolve() -> int:
+    from superset.commands.deletion_retention.window import 
resolve_retention_window
+
+    return resolve_retention_window()
+
+
+def test_unset_falls_back_to_config(app_config: Config) -> None:
+    with patch(
+        "superset.commands.deletion_retention.window.get_shared_value",
+        return_value=None,
+    ):
+        assert _resolve() == 30
+
+
+def test_shared_value_overrides_config(app_config: Config) -> None:
+    with patch(
+        "superset.commands.deletion_retention.window.get_shared_value",
+        return_value=7,
+    ):
+        assert _resolve() == 7
+
+
+def test_zero_shared_value_is_preserved_not_coerced(app_config: Config) -> 
None:
+    # `0` is a meaningful "disable"; it must survive (never `or`-coerced to 
30).
+    with patch(
+        "superset.commands.deletion_retention.window.get_shared_value",
+        return_value=0,
+    ):
+        assert _resolve() == 0
+
+
+def test_malformed_shared_value_falls_back(app_config: Config) -> None:
+    for bad in ("oops", -3, True, 1.5):
+        with patch(
+            "superset.commands.deletion_retention.window.get_shared_value",
+            return_value=bad,
+        ):
+            assert _resolve() == 30
+
+
+def test_window_zero_disables_the_task(app_context: None) -> None:
+    # A zero window short-circuits the purge entirely.
+    import superset.tasks.deletion_retention as mod
+
+    with patch.object(mod, "_soft_delete_models") as models:
+        result = mod._purge_impl(0, dry_run=False)
+    assert result == {"skipped": 1}
+    models.assert_not_called()
+
+
+def test_clock_uses_now_not_utcnow() -> None:
+    # The cutoff uses the same clock as the soft-delete substrate's deleted_at.
+    import inspect
+
+    import superset.tasks.deletion_retention as mod
+
+    src = inspect.getsource(mod._purge_impl)
+    assert "datetime.now()" in src
+    assert "datetime.utcnow()" not in src
+
+
+def test_default_config_is_safe() -> None:
+    from superset import config
+
+    assert config.SUPERSET_SOFT_DELETE_RETENTION_DAYS == 30
+    assert config.SUPERSET_SOFT_DELETE_PURGE_DRY_RUN is True
+
+
+def test_default_celery_config_registers_daily_purge() -> None:
+    from superset import config
+
+    assert "superset.tasks.deletion_retention" in config.CeleryConfig.imports
+    entry: dict[str, Any] = config.CeleryConfig.beat_schedule[
+        "deletion_retention.purge_soft_deleted"
+    ]
+    assert entry["task"] == "deletion_retention.purge_soft_deleted"
+
+
+def test_purge_model_counts_only_committed_deletions(app_context: None) -> 
None:
+    import superset.tasks.deletion_retention as mod
+    from superset.commands.deletion_retention.purge_cascade import 
CascadeResult
+    from superset.models.slice import Slice
+
+    lost_race = CascadeResult(
+        purged=False, entity_type="chart", entity_uuid="lost-race"
+    )
+    with (
+        patch.object(mod, "_iter_eligible_ids", return_value=[[1]]),
+        patch.object(mod, "_purge_one", return_value=lost_race),
+    ):
+        result = mod._purge_model(Slice, datetime.now(), dry_run=False)

Review Comment:
   **Suggestion:** Add a type annotation for this local result value to keep 
test logic fully typed under the enforced type-hint rule. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   This local variable is assigned the return value of a function and can be 
annotated, but no type hint is present. That is a real omission under the 
type-hint rule.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7515a3b0486547199db93c9c8ae73a69&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=7515a3b0486547199db93c9c8ae73a69&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/tasks/test_deletion_retention.py
   **Line:** 129:129
   **Comment:**
        *Custom Rule: Add a type annotation for this local result value to keep 
test logic fully typed under the enforced type-hint rule.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=ec661d837075ed3c58f04bb4ff763cf3dc2127cdfc4d2331321eb9e3d64ad964&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41549&comment_hash=ec661d837075ed3c58f04bb4ff763cf3dc2127cdfc4d2331321eb9e3d64ad964&reaction=dislike'>๐Ÿ‘Ž</a>



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