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


##########
tests/unit_tests/models/test_time_filter_timezone.py:
##########
@@ -0,0 +1,76 @@
+# 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.
+"""Tests for dataset-timezone handling in ``get_time_filter`` (PR #37014)."""
+
+from __future__ import annotations
+
+from datetime import datetime
+
+from flask import Flask
+
+from superset.connectors.sqla.models import SqlaTable, TableColumn
+from superset.models.core import Database
+
+
+def _table(extra: str | None) -> tuple[SqlaTable, TableColumn]:
+    database = Database(database_name="test_db", sqlalchemy_uri="sqlite://")
+    time_col = TableColumn(column_name="last_modified", is_dttm=1, 
type="TIMESTAMP")
+    table = SqlaTable(
+        table_name="events",
+        columns=[time_col],
+        main_dttm_col="last_modified",
+        database=database,
+        extra=extra,
+    )
+    return table, time_col

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require inline docstrings for small helper functions in test files 
when the function name and surrounding test context already make the purpose 
clear.
   
   **Applied to:**
     - `**/test/**`
     - `**/tests/**`
     - `**/*test*.<ext>`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/models/helpers.py:
##########
@@ -2762,19 +2780,47 @@ def get_time_filter(  # pylint: 
disable=too-many-arguments
             )
         )
 
+        # Apply timezone conversion for time filter boundaries
+        # This converts user's local time boundaries to UTC for querying 
UTC-stored data
+        adjusted_start, adjusted_end = start_dttm, end_dttm
+        dataset_timezone = self.get_dataset_timezone()
+
+        if dataset_timezone and (start_dttm or end_dttm):
+            try:
+                tz = ZoneInfo(dataset_timezone)
+
+                # The datetimes from the UI are naive (no timezone info)
+                # We interpret them as being in the dataset's configured 
timezone
+                # and convert them to UTC for comparison with UTC-stored data
+                if start_dttm:
+                    local_start = start_dttm.replace(tzinfo=tz)
+                    adjusted_start = 
local_start.astimezone(timezone.utc).replace(
+                        tzinfo=None
+                    )
+                if end_dttm:
+                    local_end = end_dttm.replace(tzinfo=tz)
+                    adjusted_end = local_end.astimezone(timezone.utc).replace(
+                        tzinfo=None
+                    )

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag `.replace(tzinfo=tz)` in `get_time_filter` when the inputs are 
UI time-filter boundaries that are intentionally naive; interpreting those 
boundaries in the dataset timezone is expected for this path.
   
   **Applied to:**
     - `superset/models/helpers.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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