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


##########
superset/datasource/schemas.py:
##########
@@ -140,3 +147,103 @@ def get_changed_on_delta_humanized(self, obj: 
SemanticView) -> str:
 
     def get_changed_on_utc(self, obj: SemanticView) -> str:
         return obj.changed_on_utc()
+
+
+class DatasourceQueryOrderSchema(Schema):
+    """One ordering term, mirroring SemanticQuery's OrderTuple."""
+
+    column = fields.String(
+        required=True,
+        metadata={"description": "Metric or dimension name to sort by."},
+    )
+    descending = fields.Boolean(
+        load_default=True,
+        metadata={"description": "Sort this column descending."},
+    )
+
+
+class DatasourceQuerySchema(Schema):
+    """Name-based query request for POST /datasource/<type>/<id>/query.
+
+    Field names mirror the semantic-layer vocabulary (``dimensions``,
+    ``metrics``) rather than Explore's (``columns``); translation to the
+    QueryObject shape happens in ``superset.common.tabular_query``.
+    """
+
+    # Raw, not String: Metric/Column are `AdhocMetric | str` and
+    # `AdhocColumn | str`, so ad-hoc expressions are accepted for datasets
+    # exactly as ChartDataQueryObjectSchema accepts them. Semantic views
+    # reject ad-hoc metrics downstream, in the mapper that owns that rule.
+    metrics = fields.List(
+        fields.Raw(),
+        load_default=list,
+        metadata={
+            "description": "Saved metric names, or ad-hoc metric objects "
+            "(datasets only). See ChartDataAdhocMetricSchema."
+        },
+    )
+    dimensions = fields.List(
+        fields.Raw(),
+        load_default=list,
+        metadata={"description": "Dimension/column names to group by."},
+    )
+    filters = fields.List(
+        fields.Nested(ChartDataFilterSchema),
+        load_default=list,
+        metadata={"description": "Filters to apply, AND-ed together."},
+    )
+    time_range = fields.String(
+        allow_none=True,
+        load_default=None,
+        metadata={"description": "e.g. 'Last 30 days' or '2024-01-01 : 
2024-12-31'."},
+    )
+    time_column = fields.String(
+        allow_none=True,
+        load_default=None,
+        metadata={
+            "description": "Temporal column the time range applies to. 
Inferred "
+            "from the datasource when omitted."
+        },
+    )
+    time_grain = fields.String(
+        allow_none=True,
+        load_default=None,
+        metadata={"description": "ISO 8601 duration, e.g. 'P1D' or 'PT1H'."},
+    )
+    limit = fields.Integer(
+        allow_none=True,
+        load_default=None,
+        validate=[Range(min=1, max=MAX_ROW_LIMIT)],
+        metadata={
+            "description": "Rows to return. Also clamped server-side by 
ROW_LIMIT."
+        },
+    )
+    offset = fields.Integer(
+        load_default=0,
+        validate=[Range(min=0)],
+        metadata={"description": "Rows to skip, for pagination."},
+    )
+    order = fields.List(
+        fields.Nested(DatasourceQueryOrderSchema),
+        load_default=list,
+        metadata={
+            "description": "Ordering terms, applied in sequence. Each carries 
its "
+            "own direction."
+        },
+    )
+    result_format = fields.Enum(
+        ChartDataResultFormat,
+        by_value=True,
+        load_default=ChartDataResultFormat.JSON,
+        metadata={
+            "description": "'json' (default) or 'arrow' for an Arrow IPC 
stream."
+        },
+    )
+    use_cache = fields.Boolean(load_default=True)
+    force = fields.Boolean(load_default=False)
+    cache_timeout = fields.Integer(allow_none=True, load_default=None)

Review Comment:
   **Suggestion:** The schema accepts any integer for `cache_timeout`, 
including values below the only supported negative sentinel (`-1`). These 
values are passed directly as `custom_cache_timeout` to the query cache, where 
backend-specific behavior or errors can result. Restrict this field to 
non-negative values, or explicitly allow only `-1` as the cache-disabled 
sentinel. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Minor ๐Ÿงน</summary>
   
   ```mdx
   - โš ๏ธ Datasource query caching becomes backend-dependent for invalid negative 
values.
   - โš ๏ธ Repeated API queries may bypass caching after swallowed cache-write 
errors.
   - โš ๏ธ Existing database schema validation allows only `-1` or non-negative 
timeouts.
   ```
   </details>
   
   [![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=8876f4b73c1f40baa25f0e9182074a6c&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=8876f4b73c1f40baa25f0e9182074a6c&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/datasource/schemas.py
   **Line:** 244:244
   **Comment:**
        *Logic Error: The schema accepts any integer for `cache_timeout`, 
including values below the only supported negative sentinel (`-1`). These 
values are passed directly as `custom_cache_timeout` to the query cache, where 
backend-specific behavior or errors can result. Restrict this field to 
non-negative values, or explicitly allow only `-1` as the cache-disabled 
sentinel.
   
   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%2F43527&comment_hash=2ea91664a3156967ccb19930bcf4c54ad854f513c5a91ac40450ed0d1c0709a8&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43527&comment_hash=2ea91664a3156967ccb19930bcf4c54ad854f513c5a91ac40450ed0d1c0709a8&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