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


##########
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:** This signature change drops `None` from the accepted input 
type, but the function’s documented/tested contract still includes `None` and 
the body calls `value.isdigit()` without a null guard. Passing `None` now will 
raise an exception instead of returning `None`, so restore `None` in the 
accepted type and keep an explicit `None` early return. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Integration test `test_cast_to_num` fails due to AttributeError.
   - ⚠️ Numeric filter conversion in helpers.py uses cast_to_num.
   - ⚠️ Function docs and doctests still include None input.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Run the integration test suite, specifically `test_cast_to_num` in
   `tests/integration_tests/utils_tests.py:404-410`, which imports 
`cast_to_num` from
   `superset.utils.core` at lines 42-46.
   
   2. The test calls `cast_to_num(None)` (see 
`tests/integration_tests/utils_tests.py:409`),
   expecting the function to return `None` as asserted in the test and 
documented by the
   doctest examples in `superset/utils/core.py:56-59`.
   
   3. The call reaches `cast_to_num` defined in `superset/utils/core.py:41-72`, 
where the
   signature is `def cast_to_num(value: float | int | str) -> float | int | 
None:` and the
   implementation executes:
   
      - `if isinstance(value, (int, float)):` at line 65, which is false for 
`None`,
   
      - then `if value.isdigit():` at line 67.
   
   4. Because `value` is `None`, `value.isdigit()` raises `AttributeError: 
'NoneType' object
   has no attribute 'isdigit'`, causing the test and any real caller passing 
`None` (such as
   numeric filter handling in `superset/models/helpers.py:2658-2673` which 
delegates to
   `utils.cast_to_num(value)`) to fail unexpectedly instead of returning `None` 
as per the
   documented contract.
   ```
   </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=698989e882284e19816ccd8666452d2c&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=698989e882284e19816ccd8666452d2c&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: This signature change drops `None` from the accepted 
input type, but the function’s documented/tested contract still includes `None` 
and the body calls `value.isdigit()` without a null guard. Passing `None` now 
will raise an exception instead of returning `None`, so restore `None` in the 
accepted type and keep an explicit `None` early return.
   
   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%2F41775&comment_hash=f4147b93a30b08e59f6f4c56ac58d9178ece48733011ad11d6da7b684f990f4b&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41775&comment_hash=f4147b93a30b08e59f6f4c56ac58d9178ece48733011ad11d6da7b684f990f4b&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