Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[BUG] Exceptions in Background Callback Cause `InvalidCallbackReturnValue` When Using Custom Error Handler

Đang mở
#3,628 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@T4rk1n đang làm issue này rồi.

Từ ngày 4/3/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

Environment

  • The server runs on Debian 13 on x86.
  • Python 3.14.3 (main, Feb 3 2026, 22:52:18) [Clang 21.1.4 ] on linux
  • The issue is not frontend-related.
Packages
dash                 4.0.0

Bug Description

When using a custom error handler with a background callback with no outputs, exceptions raised in that callback cause an InvalidCallbackReturnValue exception to be raised.

Expected Behavior

Exceptions raised in the background callback are handled by the custom error handler. No further exceptions occur.

Actual Behavior

After the exception is handled by the custom error handler as expected, Dash’s error handling code replaces the output value with NoUpdate(). Later on the output value is expected to be None because the callback has no outputs, so an InvalidCallbackReturnValue exception is raised.

Minimal Working Example
  1. Install Dash and diskcache:
    pip install dash[diskcache]
    
  2. Create a file main.py with the following contents:
    import diskcache
    from dash import Dash, DiskcacheManager, Input, callback, dcc, html
    
    cache = diskcache.Cache("./cache")
    background_callback_manager = DiskcacheManager(cache)
    
    
    def custom_error_handler(err):
        print("The app raised an exception.")
    
    
    app = Dash(
        background_callback_manager=background_callback_manager,
        on_error=custom_error_handler,
    )
    
    app.layout = html.Div(
        [
            dcc.Input(id="input-number", type="number", value=1),
        ]
    )
    
    
    @callback(
        Input("input-number", "value"),
        background=True,
    )
    def update_output(_value):
        raise ValueError(
            "This exception is supposed to be caught by custom_error_handler and not shown "
            "in the developer tools."
        )
    
    
    if __name__ == "__main__":
        app.run(debug=True)
    
    
  3. Run the application:
    python3.14 main.py
    
  4. Open the web application in your browser:
    firefox http://127.0.0.1:8050/
    
  5. Cause the exception by clicking a spinner button.
Analysis

The issue does not arise if background is set to False because the output of the error handler is treated differently in each case. In both cases, the error handler is called on the error and its return value is written to output_value.

  • When background=False, output_value is left as is here because output_spec is Falsy:
    if output_value is None and output_spec:
        output_value = NoUpdate()
    
  • When background=True, output_value is replaced here because output_spec is not considered:
    if output_value is None:
        output_value = NoUpdate()
    

I do not know the rationale behind this decision, but it appears to break the intended behavior.

Ngôn ngữ chính
Python
Star
24.4k
Fork
2.3k
Merge trung bình
1 ngày 21 giờ
Pull request đã merge (30 ngày)
19

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của plotly/dash

Tất cả issue của plotly/dash

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.