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


##########
superset/utils/core.py:
##########
@@ -417,7 +417,7 @@ def sanitize_cookie_token(token: str | None) -> str | None:
     return None
 
 
-def cast_to_num(value: float | int | str | None) -> float | int | None:
+def cast_to_num(value: float | int | str) -> float | int | None:

Review Comment:
   **Suggestion:** The parameter type was narrowed to exclude `None`, but this 
utility’s documented contract (and existing tests) still treat `None` as a 
valid input returning `None`; this creates an API contract mismatch for typed 
callers and leaves a real runtime failure path when optional values reach 
`value.isdigit()`. Restore `None` in the input type and handle it explicitly 
before string operations. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Integration test test_cast_to_num crashes on None input.
   - ⚠️ Future optional callers risk AttributeError on None values.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open `superset/utils/core.py` and locate `cast_to_num` at line 420, which 
is defined as
   `def cast_to_num(value: float | int | str) -> float | int | None:` and 
implemented with
   `if value.isdigit():` at line 446 without any prior `None` guard (lines 
444–451 in the PR
   hunk).
   
   2. Open `superset/tests/integration_tests/utils_tests.py` and find 
`test_cast_to_num` at
   lines 404–410, where `cast_to_num(None) is None` is asserted at line 409 
(verified via
   Grep output and BulkRead).
   
   3. Run the integration test, for example `pytest
   
superset/tests/integration_tests/utils_tests.py::TestUtils::test_cast_to_num`, 
so that the
   test calls `cast_to_num(None)` as defined in step 2.
   
   4. Observe that inside `cast_to_num`, `value` is `None`, so the 
`isinstance(value, (int,
   float))` check at line 444 fails, and execution reaches `if 
value.isdigit():` at line 446,
   which raises `AttributeError: 'NoneType' object has no attribute 'isdigit'`, 
causing the
   test to error and demonstrating the runtime failure for `None` inputs 
despite the
   documented doctest `>>> cast_to_num(None) is None` at lines 435–437.
   ```
   </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=62d96c80d68c4ebbbbae52b086420823&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=62d96c80d68c4ebbbbae52b086420823&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/utils/core.py
   **Line:** 420:420
   **Comment:**
        *Api Mismatch: The parameter type was narrowed to exclude `None`, but 
this utility’s documented contract (and existing tests) still treat `None` as a 
valid input returning `None`; this creates an API contract mismatch for typed 
callers and leaves a real runtime failure path when optional values reach 
`value.isdigit()`. Restore `None` in the input type and handle it explicitly 
before string operations.
   
   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%2F41770&comment_hash=2923794ca2a38a6bcf7353b25a06e00342e996f06d58d768b82d2bfcdcb9c9dc&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41770&comment_hash=2923794ca2a38a6bcf7353b25a06e00342e996f06d58d768b82d2bfcdcb9c9dc&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