Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

This change addresses an issue where the UnsupportedTypeError exception produced a messy and unhelpful error message. The original implementation displayed the raw representation of the supported types, including memory addresses, which was not useful for debugging. This commit refactors the exception to output a clean, sorted list of supported type names, making it easier for users to understand and correct their code. Additionally, new unit tests have been added to verify the new error message format and ensure the exception is raised correctly.


PR created automatically by Jules for task 17087358634619041143

The `UnsupportedTypeError` now provides a more user-friendly error message by displaying a sorted, comma-separated list of supported type names instead of the raw object representations. This improves clarity and makes it easier for developers to identify the correct types to use.

Added a new test file, `tests/unit/functions/test_function_typing.py`, with unit tests to ensure the error message is formatted correctly for different types of collections (dictionaries and sets) and that the exception is raised with the expected message.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Oct 28, 2025
@tswast tswast changed the title Improve UnsupportedTypeError Message and Add Tests feat: improve UnsupportedTypeError message Oct 28, 2025
@tswast tswast marked this pull request as ready for review October 28, 2025 18:27
@tswast tswast requested review from a team as code owners October 28, 2025 18:27
@tswast tswast requested a review from TrevorBergeron October 28, 2025 18:27
tswast
tswast previously approved these changes Oct 28, 2025
err = function_typing.UnsupportedTypeError(
decimal.Decimal, {int: "INT64", float: "FLOAT64"}
)
assert "Decimal" in str(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: insert empty lines between "arrange" "act" "assert" blocks: go/unit-testing-practices?polyglot=python#structure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@google-labs-jules please address this nit: insert empty lines between "arrange" "act" "assert" blocks: go/unit-testing-practices?polyglot=python#structure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I've restructured the tests to improve readability.

tswast
tswast previously approved these changes Oct 29, 2025
sycai
sycai previously approved these changes Oct 29, 2025
@tswast tswast enabled auto-merge (squash) October 29, 2025 19:07
@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 29, 2025
@bigframes-bot bigframes-bot removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 29, 2025
@tswast
Copy link
Collaborator

tswast commented Oct 29, 2025

@google-labs-jules This test failure looks like a real one. Please fix.

____________________ test_remote_function_unsupported_type _____________________
[gw5] linux -- Python 3.9.20 /tmpfs/src/github/python-bigquery-dataframes/.nox/system-3-9/bin/python

session = <bigframes.session.Session object at 0x14f51d796b50>
dataset_id_permanent = 'bigframes-dev.bigframes_testing'
bq_cf_connection = 'bigframes-rf-conn'

    @pytest.mark.flaky(retries=2, delay=120)
    def test_remote_function_unsupported_type(
        session,
        dataset_id_permanent,
        bq_cf_connection,
    ):
        # Remote functions do not support tuple return types.
        def func_tuple(x):
            return (x, x, x)
    
        with pytest.raises(
            ValueError,
            match=r"'typing\.Sequence\[int\]' must be one of the supported types",
        ):
>           bff.remote_function(
                input_types=int,
                output_type=Sequence[int],
                session=session,
                dataset=dataset_id_permanent,
                bigquery_connection=bq_cf_connection,
                reuse=True,
                name=get_function_name(func_tuple),
                cloud_function_service_account="default",
            )(func_tuple)

[tests/system/small/functions/test_remote_function.py:1651](https://cs.corp.google.com/piper///depot/google3/tests/system/small/functions/test_remote_function.py?l=1651): 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[bigframes/functions/_function_session.py:621](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/_function_session.py?l=621): in wrapper
    udf_sig = udf_def.UdfSignature.from_py_signature(py_sig)
[bigframes/functions/udf_def.py:139](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/udf_def.py?l=139): in from_py_signature
    output_bq_type = function_typing.sdk_type_from_python_type(
[bigframes/functions/function_typing.py:82](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/function_typing.py?l=82): in sdk_type_from_python_type
    raise UnsupportedTypeError(t, RF_SUPPORTED_IO_PYTHON_TYPES)
[bigframes/functions/function_typing.py:71](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/function_typing.py?l=71): in __init__
    f"'{type_.__name__}' must be one of the supported types ({supported_types_str}) "
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = typing.Sequence[int], attr = '__name__'

    def __getattr__(self, attr):
        # We are careful for copy and pickle.
        # Also for simplicity we don't relay any dunder names
        if '__origin__' in self.__dict__ and not _is_dunder(attr):
            return getattr(self.__origin__, attr)
>       raise AttributeError(attr)
E       AttributeError: __name__

/[usr/local/lib/python3.9/typing.py:711](https://cs.corp.google.com/piper///depot/google3/usr/local/lib/python3.9/typing.py?l=711): AttributeError

@google-labs-jules
Copy link
Contributor Author

@google-labs-jules This test failure looks like a real one. Please fix.

____________________ test_remote_function_unsupported_type _____________________
[gw5] linux -- Python 3.9.20 /tmpfs/src/github/python-bigquery-dataframes/.nox/system-3-9/bin/python

session = <bigframes.session.Session object at 0x14f51d796b50>
dataset_id_permanent = 'bigframes-dev.bigframes_testing'
bq_cf_connection = 'bigframes-rf-conn'

    @pytest.mark.flaky(retries=2, delay=120)
    def test_remote_function_unsupported_type(
        session,
        dataset_id_permanent,
        bq_cf_connection,
    ):
        # Remote functions do not support tuple return types.
        def func_tuple(x):
            return (x, x, x)
    
        with pytest.raises(
            ValueError,
            match=r"'typing\.Sequence\[int\]' must be one of the supported types",
        ):
>           bff.remote_function(
                input_types=int,
                output_type=Sequence[int],
                session=session,
                dataset=dataset_id_permanent,
                bigquery_connection=bq_cf_connection,
                reuse=True,
                name=get_function_name(func_tuple),
                cloud_function_service_account="default",
            )(func_tuple)

[tests/system/small/functions/test_remote_function.py:1651](https://cs.corp.google.com/piper///depot/google3/tests/system/small/functions/test_remote_function.py?l=1651): 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[bigframes/functions/_function_session.py:621](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/_function_session.py?l=621): in wrapper
    udf_sig = udf_def.UdfSignature.from_py_signature(py_sig)
[bigframes/functions/udf_def.py:139](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/udf_def.py?l=139): in from_py_signature
    output_bq_type = function_typing.sdk_type_from_python_type(
[bigframes/functions/function_typing.py:82](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/function_typing.py?l=82): in sdk_type_from_python_type
    raise UnsupportedTypeError(t, RF_SUPPORTED_IO_PYTHON_TYPES)
[bigframes/functions/function_typing.py:71](https://cs.corp.google.com/piper///depot/google3/bigframes/functions/function_typing.py?l=71): in __init__
    f"'{type_.__name__}' must be one of the supported types ({supported_types_str}) "
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = typing.Sequence[int], attr = '__name__'

    def __getattr__(self, attr):
        # We are careful for copy and pickle.
        # Also for simplicity we don't relay any dunder names
        if '__origin__' in self.__dict__ and not _is_dunder(attr):
            return getattr(self.__origin__, attr)
>       raise AttributeError(attr)
E       AttributeError: __name__

/[usr/local/lib/python3.9/typing.py:711](https://cs.corp.google.com/piper///depot/google3/usr/local/lib/python3.9/typing.py?l=711): AttributeError

You were right, that was a real test failure. I've pushed a fix that should resolve the AttributeError and handle generic types from the typing module correctly. The unit tests are now passing.

This commit fixes a test failure caused by an `AttributeError` when handling generic types from the `typing` module in the `UnsupportedTypeError` class.

The `__init__` method of `UnsupportedTypeError` has been updated to check if a type is a generic from the `typing` module and, if so, convert it to a string directly to get the full type representation (e.g., `list[str]`). This ensures that the error message is generated correctly without raising an `AttributeError`.

A new unit test has also been added to `tests/unit/functions/test_function_typing.py` to verify the fix.
@tswast tswast dismissed stale reviews from sycai and themself via 055b45e October 29, 2025 21:33
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: m Pull request size is medium. labels Oct 29, 2025
@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 30, 2025
@bigframes-bot bigframes-bot removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 30, 2025
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. Another bad merge. I'll try to get Jules to sync to main again.

This commit fixes a test failure caused by an `AttributeError` when handling generic types from the `typing` module in the `UnsupportedTypeError` class.

The `__init__` method of `UnsupportedTypeError` has been updated to check if a type is a generic from the `typing` module and, if so, convert it to a string directly to get the full type representation (e.g., `list[str]`). This ensures that the error message is generated correctly without raising an `AttributeError`.

A new unit test has also been added to `tests/unit/functions/test_function_typing.py` to verify the fix.
@tswast
Copy link
Collaborator

tswast commented Oct 30, 2025

I give up on Jules. I'll try to fix myself.

@tswast tswast closed this Oct 30, 2025
auto-merge was automatically disabled October 30, 2025 18:04

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants