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


##########
superset/db_engine_specs/postgres.py:
##########
@@ -256,6 +258,35 @@ def fetch_data(cls, cursor: Any, limit: int | None = None) 
-> list[tuple[Any, ..
     def epoch_to_dttm(cls) -> str:
         return "(timestamp 'epoch' + {col} * interval '1 second')"
 
+    @classmethod
+    def get_timestamp_expr(
+        cls,
+        col: ColumnClause,
+        pdf: str | None,
+        time_grain: str | None,
+    ) -> TimestampExpression:
+        """
+        Construct a timestamp expression while preserving pure ``DATE`` 
semantics.
+
+        Applying ``DATE_TRUNC`` to a ``DATE`` column implicitly casts the 
value to
+        ``TIMESTAMP``, which can trigger unwanted timezone conversion on the 
client
+        and shift the displayed date by a day. To avoid this, the truncated 
value is
+        cast back to ``DATE`` when the source column is a pure ``DATE`` type.

Review Comment:
   **Suggestion:** The docstring states that applying `DATE_TRUNC` to a `DATE` 
produces `TIMESTAMP WITH TIME ZONE`, which is factually incorrect for 
PostgreSQL’s implicit cast path here and can mislead future maintainers when 
debugging timezone behavior. Update the text to match the actual resulting 
timestamp type semantics. [comment mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Minor 🧹</summary>
   
   ```mdx
   - ⚠️ Slightly imprecise docstring about PostgreSQL timestamp type.
   - ⚠️ Documentation nuance only; runtime behavior remains correct.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open `superset/db_engine_specs/postgres.py` and inspect the docstring for
   `get_timestamp_expr` at lines 268-277, which states that applying 
`DATE_TRUNC` to a `DATE`
   “implicitly casts the value to `TIMESTAMP`”.
   
   2. Compare this wording to PostgreSQL’s precise behavior for `DATE_TRUNC` 
and its implicit
   cast of `DATE` inputs, noting that the docstring simplifies the result to a 
generic
   `TIMESTAMP` without distinguishing `TIMESTAMP WITHOUT TIME ZONE` vs 
`TIMESTAMP WITH TIME
   ZONE`.
   
   3. Observe that the implementation below the docstring (lines 278-288) 
correctly calls
   `super().get_timestamp_expr` and then conditionally wraps the result with 
`CAST(... AS
   DATE)` for pure `Date` columns, which aligns with the documented intent of 
preserving
   calendar date semantics.
   
   4. Since the docstring does not drive any runtime logic and accurately 
captures the
   high-level behavior (DATE is truncated then cast back to DATE), any mismatch 
with
   PostgreSQL’s exact internal type naming is purely a documentation nuance and 
does not lead
   to a reproducible bug or inconsistent behavior in query generation.
   ```
   </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=59c0330f85c44b1cbb32b734997a1753&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=59c0330f85c44b1cbb32b734997a1753&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/db_engine_specs/postgres.py
   **Line:** 271:274
   **Comment:**
        *Comment Mismatch: The docstring states that applying `DATE_TRUNC` to a 
`DATE` produces `TIMESTAMP WITH TIME ZONE`, which is factually incorrect for 
PostgreSQL’s implicit cast path here and can mislead future maintainers when 
debugging timezone behavior. Update the text to match the actual resulting 
timestamp type semantics.
   
   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%2F42329&comment_hash=20f45924df45d9fa97fdcc6fffe26caeed536629ee05d5835bf5b7f0b28d171c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42329&comment_hash=20f45924df45d9fa97fdcc6fffe26caeed536629ee05d5835bf5b7f0b28d171c&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