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


##########
superset/common/query_context_processor.py:
##########
@@ -151,6 +155,131 @@ def is_summable(series: pd.Series) -> bool:
     return infer_dtype(series, skipna=True) == "decimal"
 
 
+def _resolve_override(overrides: dict[str, Any], key: str, inherited: Any) -> 
Any:
+    """Return the value an annotation layer override resolves to.
+
+    An absent key means "no override". A key stored as ``None`` means
+    "inherit from the host chart", which is what the layer popover checkboxes
+    write, and resolves to ``inherited``. Any other value is used as given.
+    """
+    if key not in overrides:
+        return None
+    value = overrides[key]
+    return inherited if value is None else value
+
+
+def _host_time_range(host_query: QueryObject | None) -> str | None:
+    """Return the host chart's time range expression, or ``None`` without 
one."""
+    if host_query is None:
+        return None
+    has_temporal_filter = any(
+        flt.get("op") == FilterOperator.TEMPORAL_RANGE for flt in 
host_query.filter
+    )
+    if not host_query.time_range and not has_temporal_filter:
+        return None
+    return get_time_range_from_filters(
+        host_query.time_range, host_query.filter, host_query.columns
+    )
+
+
+def _host_time_grain(host_query: QueryObject | None) -> str | None:
+    """Return the host chart's time grain, or ``None`` when it has none.
+
+    Charts with a generic x-axis carry the grain on their BASE_AXIS column;
+    legacy charts carry it in ``extras["time_grain_sqla"]``.
+    """
+    if host_query is None:
+        return None
+    for column in host_query.columns:
+        if is_adhoc_column(column) and column.get("columnType") == "BASE_AXIS":
+            if grain := column.get("timeGrain"):
+                return grain
+    return host_query.extras.get("time_grain_sqla")
+
+
+def _apply_time_range(
+    query_context: QueryContext, time_range: str, time_column: Any
+) -> None:
+    """Run every query of an annotation source chart over ``time_range``.
+
+    Mirrors ``QueryContextFactory._apply_filters``: the range is written to
+    ``time_range`` and to every TEMPORAL_RANGE filter, which is where charts
+    with a generic x-axis read it, and ``from_dttm``/``to_dttm`` are
+    recomputed for charts on the legacy ``granularity`` path. A source query
+    without a TEMPORAL_RANGE filter gets one on the layer's time column when
+    that column belongs to the source dataset.
+    """
+    column_names = query_context.datasource.column_names
+    for query_object in query_context.queries:
+        query_object.time_range = time_range
+        temporal_filters = [
+            flt
+            for flt in query_object.filter
+            if flt.get("op") == FilterOperator.TEMPORAL_RANGE
+        ]
+        if temporal_filters:
+            for flt in temporal_filters:
+                flt["val"] = time_range
+        elif isinstance(time_column, str) and time_column in column_names:
+            query_object.filter.append(
+                {
+                    "col": time_column,
+                    "op": FilterOperator.TEMPORAL_RANGE,
+                    "val": time_range,
+                }
+            )
+        else:
+            logger.debug(
+                "Annotation source query has no TEMPORAL_RANGE filter and the "
+                "layer time column %r is not a column of the source dataset; "
+                "no time range filter was added",
+                time_column,
+            )
+        query_object.from_dttm, query_object.to_dttm = 
get_since_until_from_time_range(
+            time_range, extras=query_object.extras
+        )

Review Comment:
   **Suggestion:** When a source chart has `time_shift`, these bounds omit it, 
so the query uses a different period than its unchanged time-shift setting 
implies.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes` ยท ๐Ÿท๏ธ `Logic error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![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=a2786548824642aeb08bcf4d75898710&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=a2786548824642aeb08bcf4d75898710&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/common/query_context_processor.py
   **Line:** 238:240
   **Comment:**
        *Logic Error: When a source chart has `time_shift`, these bounds omit 
it, so the query uses a different period than its unchanged time-shift setting 
implies.
   
   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%2F45797&comment_hash=c87b000ddfd73511e442e1363196d9b5744cf0024b7c47928c86da3a233fddf6&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45797&comment_hash=c87b000ddfd73511e442e1363196d9b5744cf0024b7c47928c86da3a233fddf6&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