Repository: plotly/dash
File: dash/_callback.py (Python)

Code before:
                current_key = callback_manager.build_cache_key(
                    func,
                    # Inputs provided as dict is kwargs.
                    func_args if func_args else func_kwargs,
                    long.get("cache_args_to_ignore", []),
                )

                if old_job:
                    for job in old_job:
                        callback_manager.terminate_job(job)

                if not cache_key:
                    cache_key = current_key

                    job_fn = callback_manager.func_registry.get(long_key)

                    ctx_value = AttributeDict(**context_value.get())
                    ctx_value.ignore_register_page = True

                    job = callback_manager.call_job_fn(
                        cache_key,
                        job_fn,
                        func_args if func_args else func_kwargs,
                        ctx_value,
                    )

                    data = {
                        "cacheKey": cache_key,
                        "job": job,
                    }

                    cancel = long.get("cancel")
                    if cancel:
                        data["cancel"] = cancel

                    progress_default = long.get("progressDefault")
                    if progress_default:
                        data["progressDefault"] = {
                            str(o): x
                            for o, x in zip(progress_outputs, progress_default)
                        }
                    return to_json(data)
                if progress_outputs:
                    # Get the progress before the result as it would be erased after the results.
                    progress = callback_manager.get_progress(cache_key)
                    if progress:
                        response["progress"] = {
                            str(x): progress[i] for i, x in enumerate(progress_outputs)
                        }

                output_value = callback_manager.get_result(cache_key, job_id)

Review comment (suggestion):
When I try to run this with a background task, I get a callback error of `kombu.exceptions.EncodeError: Object of type Response is not JSON serializable`. It works if I pop `'dash_response'` and `'background_callback_manager'` from this dict though

Code after:
                current_key = callback_manager.build_cache_key(
                    func,
                    # Inputs provided as dict is kwargs.
                    func_args if func_args else func_kwargs,
                    long.get("cache_args_to_ignore", []),
                )

                if old_job:
                    for job in old_job:
                        callback_manager.terminate_job(job)

                if not cache_key:
                    cache_key = current_key

                    job_fn = callback_manager.func_registry.get(long_key)

                    ctx_value = AttributeDict(**context_value.get())
                    ctx_value.ignore_register_page = True
                    ctx_value.pop("background_callback_manager")
                    ctx_value.pop("dash_response")

                    job = callback_manager.call_job_fn(
                        cache_key,
                        job_fn,
                        func_args if func_args else func_kwargs,
                        ctx_value,
                    )

                    data = {
                        "cacheKey": cache_key,
                        "job": job,
                    }

                    cancel = long.get("cancel")
                    if cancel:
                        data["cancel"] = cancel

                    progress_default = long.get("progressDefault")
                    if progress_default:
                        data["progressDefault"] = {
                            str(o): x
                            for o, x in zip(progress_outputs, progress_default)
                        }
                    return to_json(data)
                if progress_outputs:
                    # Get the progress before the result as it would be erased after the results.
                    progress = callback_manager.get_progress(cache_key)
                    if progress:
                        response["progress"] = {
                            str(x): progress[i] for i, x in enumerate(progress_outputs)
                        }