codeant-ai-for-open-source[bot] commented on code in PR #42295:
URL: https://github.com/apache/superset/pull/42295#discussion_r3626627849
##########
tests/unit_tests/security/manager_test.py:
##########
@@ -669,6 +669,101 @@ def test_query_context_modified_tampered(
assert query_context_modified(query_context)
+def test_query_context_modified_singular_metric_param(
+ mocker: MockerFixture,
+) -> None:
+ """
+ A chart storing its metric under the singular ``metric`` params key (big
+ number, world map, ...) generates a payload with a plural ``metrics`` list;
+ replaying the chart's own metric is not tampering.
+ """
+ query_context = mocker.MagicMock()
+ query_context.slice_.id = 42
+ query_context.slice_.query_context = None
+ query_context.slice_.params_dict = {
+ "metric": "sum__SP_POP_TOTL",
+ "groupby": [],
+ }
+
+ query_context.form_data = {
+ "slice_id": 42,
+ "metric": "sum__SP_POP_TOTL",
+ }
Review Comment:
**Suggestion:** The test claims to validate the generated payload shape
where metrics are sent as a plural `metrics` list, but the setup uses singular
`metric` in `form_data`. This mismatch means the test does not exercise the
scenario described and can miss regressions in handling plural metric payloads;
align the payload key with the documented case. [docstring mismatch]
<details>
<summary><b>Severity Level:</b> Minor ๐งน</summary>
```mdx
- โ ๏ธ Suggestion misinterprets docstring vs payload representation.
- โ ๏ธ No incorrect behavior in tamper detection logic.
```
</details>
<details>
<summary><b>Steps of Reproduction โ
</b></summary>
```mdx
1. Run the unit tests in `tests/unit_tests/security/manager_test.py`,
focusing on
`test_query_context_modified_singular_metric_param` (lines 672โ693).
2. Observe that the test sets `query_context.slice_.params_dict` with a
singular `metric`
key and `groupby` (lines 683โ686), matching the chart params described in
the docstring
(lines 675โ678).
3. Observe that the generated payload is represented by
`query_context.queries =
[QueryObject(metrics=["sum__SP_POP_TOTL"])]` (line 692), which is the plural
`metrics`
list referenced in the docstring; `form_data` (lines 688โ691) models the
control request,
not the payload.
4. Confirm that `query_context_modified(query_context)` (line 693) evaluates
to `False`,
showing the test correctly validates that a singular `metric` control value
yielding a
plural `metrics` payload is not treated as tampering; there is no behavioral
bug, and the
supposed mismatch is only a misreading of the docstring, making this
suggestion
effectively a non-issue.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=65578df5146d47e494c3b9f29f55f3fa&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=65578df5146d47e494c3b9f29f55f3fa&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:** tests/unit_tests/security/manager_test.py
**Line:** 675:691
**Comment:**
*Docstring Mismatch: The test claims to validate the generated payload
shape where metrics are sent as a plural `metrics` list, but the setup uses
singular `metric` in `form_data`. This mismatch means the test does not
exercise the scenario described and can miss regressions in handling plural
metric payloads; align the payload key with the documented case.
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%2F42295&comment_hash=29a538d7932f0e71e9856f3f866d9938c71051bca72dca1bec824c1ad74cd49b&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42295&comment_hash=29a538d7932f0e71e9856f3f866d9938c71051bca72dca1bec824c1ad74cd49b&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]