bito-code-review[bot] commented on code in PR #44514:
URL: https://github.com/apache/superset/pull/44514#discussion_r4097643952


##########
superset/versioning/utils.py:
##########
@@ -44,8 +49,25 @@ def capture_enabled() -> bool:
     would let this gate pass while listeners stay detached, producing
     exactly the untracked write it exists to prevent. Restart the process
     (or re-run ``init_versioning()``) after changing the flag.
+
+    VERSIONING_CAPTURE_PREDICATE is a separate runtime decision, consulted by
+    the baseline/change listeners and CaptureUnitOfWork as well as restore.
+    The host owns tenant identity, bounded transaction memoization and expected
+    service-failure handling. Database/programming errors are not suppressed.
     """
-    return bool(current_app.config.get("ENABLE_VERSIONING_CAPTURE", False))
+    if not current_app.config.get("ENABLE_VERSIONING_CAPTURE", False):
+        return False
+    predicate: Callable[[Session], bool] | None = current_app.config.get(
+        "VERSIONING_CAPTURE_PREDICATE"
+    )
+    if predicate is None:
+        return True
+    if session is None:
+        # Deferred because extensions configures the UnitOfWork at import time.
+        from superset.extensions import db  # pylint: 
disable=import-outside-toplevel
+
+        session = db.session()

Review Comment:
   <!-- Bito Reply -->
   The suggestion to explicitly pass the session to `capture_enabled()` is 
appropriate. Relying on an implicit fallback to `db.session()` can lead to 
unexpected behavior where the gate materializes a session in contexts that were 
previously session-free, potentially causing inconsistencies in how the 
`VERSIONING_CAPTURE_PREDICATE` is evaluated per transaction. Explicitly passing 
the caller's session ensures that the predicate's decision remains stable and 
consistent with the transaction context.
   
   **superset/versioning/utils.py**
   ```
   if session is None:
           # Deferred because extensions configures the UnitOfWork at import 
time.
           from superset.extensions import db  # pylint: 
disable=import-outside-toplevel
   
           session = db.session()
   ```



##########
superset/config.py:
##########
@@ -1761,22 +1791,24 @@ def sync_theme_logo_href(
 
 def _parse_version_history_retention_days() -> int:
     """Parse the retention window without making invalid input fatal."""
-    value: str | None = 
os.environ.get("SUPERSET_VERSION_HISTORY_RETENTION_DAYS")
+    value: str | None = os.environ.get("VERSION_HISTORY_RETENTION_DAYS")
     if value is None:
         return _DEFAULT_VERSION_HISTORY_RETENTION_DAYS
     try:
-        retention_days = int(value)
+        retention_days: int = int(value)
     except ValueError:
         logger.warning(
-            "Invalid SUPERSET_VERSION_HISTORY_RETENTION_DAYS=%r; using %d",
+            "Invalid VERSION_HISTORY_RETENTION_DAYS=%r; using %d",
             value,
             _DEFAULT_VERSION_HISTORY_RETENTION_DAYS,
         )
         return _DEFAULT_VERSION_HISTORY_RETENTION_DAYS
+    if retention_days < -1:
+        logger.warning("Invalid negative VERSION_HISTORY_RETENTION_DAYS; 
skipping")
+        return 0

Review Comment:
   <!-- Bito Reply -->
   The suggestion is appropriate as it aligns the error handling in 
`_parse_version_history_retention_days` with the existing pattern in 
`_parse_soft_delete_retention_days`. By falling back to the default value 
instead of silently disabling the feature, the code becomes more robust against 
configuration errors.
   
   **superset/config.py**
   ```
   if retention_days < -1:
           logger.warning("Invalid negative VERSION_HISTORY_RETENTION_DAYS; 
using %d", _DEFAULT_VERSION_HISTORY_RETENTION_DAYS)
           return _DEFAULT_VERSION_HISTORY_RETENTION_DAYS
   ```



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