Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom callback exception callable #7558

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ahuang11
Copy link
Contributor

image image

Closes #6047

@ahuang11 ahuang11 requested a review from philippjfr December 17, 2024 20:03
@ahuang11 ahuang11 added the type: enhancement Minor feature or improvement to an existing feature label Dec 17, 2024
@philippjfr
Copy link
Member

Can you add entries in CHANGELOG.md and doc/releases.md?

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.

Project coverage is 41.63%. Comparing base (55b0634) to head (3b160b8).

Files with missing lines Patch % Lines
panel/chat/feed.py 33.33% 4 Missing ⚠️
panel/chat/_param.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7558       +/-   ##
===========================================
- Coverage   81.38%   41.63%   -39.75%     
===========================================
  Files         340      329       -11     
  Lines       51487    49172     -2315     
===========================================
- Hits        41902    20474    -21428     
- Misses       9585    28698    +19113     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11 ahuang11 added this to the v1.6.0 milestone Dec 17, 2024
@ahuang11 ahuang11 force-pushed the add_custom_callback_exception branch from f59003d to d7955cb Compare January 10, 2025 19:52
@ahuang11
Copy link
Contributor Author

Is this a bug with param?
chat_feed.callback_exception = exception_callback

panel/tests/chat/test_feed.py

Traceback (most recent call last):
  File "/Users/ahuang/repos/panel/panel/tests/chat/test_feed.py", line 1134, in test_callback_exception_async_callable
    chat_feed.callback_exception = exception_callback
  File "/Users/ahuang/miniconda3/envs/panel/lib/python3.10/site-packages/param/parameterized.py", line 528, in _f
    instance_param.__set__(obj, val)
  File "/Users/ahuang/miniconda3/envs/panel/lib/python3.10/site-packages/param/parameterized.py", line 530, in _f
    return f(self, obj, val)
  File "/Users/ahuang/miniconda3/envs/panel/lib/python3.10/site-packages/param/parameterized.py", line 1476, in __set__
    ref, deps, val, is_async = obj.param._resolve_ref(self, val)
  File "/Users/ahuang/miniconda3/envs/panel/lib/python3.10/site-packages/param/parameterized.py", line 2044, in _resolve_ref
    value = resolve_value(value, recursive=pobj.nested_refs)
  File "/Users/ahuang/miniconda3/envs/panel/lib/python3.10/site-packages/param/parameterized.py", line 186, in resolve_value
    value = eval_function_with_deps(value)
  File "/Users/ahuang/miniconda3/envs/panel/lib/python3.10/site-packages/param/parameterized.py", line 165, in eval_function_with_deps
    return function(*args, **kwargs)
TypeError: TestChatFeedCallback.test_callback_exception_async_callable.<locals>.exception_callback() missing 2 required positional arguments: 'exception' and 'instance'

If it's sync, it raises so I added a ignore, but I don't think it should be ignored:

===================================================================================================== FAILURES =====================================================================================================
______________________________________________________________________________ TestChatFeedCallback.test_callback_exception_callable _______________________________________________________________________________

cls = <class '_pytest.runner.CallInfo'>, func = <function call_and_report.<locals>.<lambda> at 0x16a7067a0>, when = 'call', reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)

    @classmethod
    def from_call(
        cls,
        func: Callable[[], TResult],
        when: Literal["collect", "setup", "call", "teardown"],
        reraise: type[BaseException] | tuple[type[BaseException], ...] | None = None,
    ) -> CallInfo[TResult]:
        """Call func, wrapping the result in a CallInfo.

        :param func:
            The function to call. Called without arguments.
        :type func: Callable[[], _pytest.runner.TResult]
        :param when:
            The phase in which the function is called.
        :param reraise:
            Exception or exceptions that shall propagate if raised by the
            function, instead of being wrapped in the CallInfo.
        """
        excinfo = None
        start = timing.time()
        precise_start = timing.perf_counter()
        try:
>           result: TResult | None = func()

../../miniconda3/envs/panel/lib/python3.10/site-packages/_pytest/runner.py:341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../miniconda3/envs/panel/lib/python3.10/site-packages/_pytest/runner.py:242: in <lambda>
    lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
../../miniconda3/envs/panel/lib/python3.10/site-packages/pluggy/_hooks.py:513: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
../../miniconda3/envs/panel/lib/python3.10/site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
../../miniconda3/envs/panel/lib/python3.10/site-packages/_pytest/threadexception.py:92: in pytest_runtest_call
    yield from thread_exception_runtest_hook()
../../miniconda3/envs/panel/lib/python3.10/site-packages/_pytest/threadexception.py:68: in thread_exception_runtest_hook
    yield
../../miniconda3/envs/panel/lib/python3.10/site-packages/_pytest/unraisableexception.py:95: in pytest_runtest_call
    yield from unraisable_exception_runtest_hook()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def unraisable_exception_runtest_hook() -> Generator[None]:
        with catch_unraisable_exception() as cm:
            try:
                yield
            finally:
                if cm.unraisable:
                    if cm.unraisable.err_msg is not None:
                        err_msg = cm.unraisable.err_msg
                    else:
                        err_msg = "Exception ignored in"
                    msg = f"{err_msg}: {cm.unraisable.object!r}\n\n"
                    msg += "".join(
                        traceback.format_exception(
                            cm.unraisable.exc_type,
                            cm.unraisable.exc_value,
                            cm.unraisable.exc_traceback,
                        )
                    )
>                   warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
E                   pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=-1, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>
E
E                   Traceback (most recent call last):
E                     File "/Users/ahuang/miniconda3/envs/panel/lib/python3.10/asyncio/base_events.py", line 773, in _call_soon
E                       handle = events.Handle(callback, args, self, context)
E                   ResourceWarning: unclosed <socket.socket fd=16, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>

../../miniconda3/envs/panel/lib/python3.10/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning
============================================================================================= short test summary info ==============================================================================================
FAILED panel/tests/chat/test_feed.py::TestChatFeedCallback::test_callback_exception_callable - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=-1, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow custom callback_exception callable in ChatFeed
2 participants