You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "devansh173 (via GitHub)" <gi...@apache.org> on 2026/09/24 16:42:14 UTC

[I] cast_to_num raises ValueError instead of returning None for non-decimal digit strings such as "²" [superset]

devansh173 opened a new issue, #44614:
URL: https://github.com/apache/superset/issues/44614

   ### Bug description
   
   `superset.utils.core.cast_to_num` is documented to return `None` when a value can't be converted to a number, but it raises an uncaught `ValueError` for strings made of characters that `str.isdigit()` accepts but `int()` does not (for example superscript digits such as `"²"`).
   
   ```python
   >>> from superset.utils.core import cast_to_num
   >>> "²".isdigit()
   True
   >>> cast_to_num("²")
   Traceback (most recent call last):
     ...
   ValueError: invalid literal for int() with base 10: '²'
   ```
   
   The function checks `value.isdigit()` and then calls `int(value)`. `isdigit()` is also true for characters in the Unicode "Digit" category that are not decimal digits (`²`, `³`, `①`, ...), and `int()` rejects those. The `float()` fallback that would have returned `None` is never reached, because the `ValueError` is raised outside the `try` block.
   
   `cast_to_num` is used when building filter values for numeric columns (`superset/models/helpers.py`, `SqlaTable.filter_values_handler` and the array-length filter), so a stray character like this in a filter value ends up as an unhandled exception instead of the value being treated as non-numeric.
   
   ### Expected behavior
   
   `cast_to_num("²")` returns `None`, like any other string that is not a number (e.g. `cast_to_num("this is not a string") is None`).
   
   ### Actual behavior
   
   `ValueError` is raised.
   
   ### Suggested fix
   
   Use `str.isdecimal()` instead of `str.isdigit()` for the integer fast path, so anything that isn't a plain decimal number falls through to the existing `try: float(value) / except ValueError: return None`.
   
   ### Environment
   
   - Superset version: master
   - Python version: 3.11
   


-- 
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: notifications-unsubscribe@superset.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] cast_to_num raises ValueError instead of returning None for non-decimal digit strings such as "²" [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas closed issue #44614: cast_to_num raises ValueError instead of returning None for non-decimal digit strings such as "²"
URL: https://github.com/apache/superset/issues/44614


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org