Skip to content

Commit b3a47bd

Browse files
committed
fix request_adapter calls
1 parent 24e79bf commit b3a47bd

4 files changed

Lines changed: 16 additions & 23 deletions

File tree

dash/_callback.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
from typing import Callable, Optional, Any, List, Tuple, Union
1+
from typing import Callable, Optional, Any, List, Tuple, Union, Dict
22
from functools import wraps
33
import collections
44
import hashlib
55
import inspect
66

7-
from functools import wraps
8-
9-
from typing import Callable, Optional, Any, List, Tuple, Union, Dict
10-
11-
import asyncio
12-
137
from .dependencies import (
148
handle_callback_args,
159
handle_grouped_callback_args,
@@ -363,7 +357,7 @@ def _initialize_context(args, kwargs, inputs_state_indices, has_output, insert_o
363357

364358
def _get_callback_manager(
365359
kwargs: dict, background: dict
366-
) -> Union[BaseBackgroundCallbackManager, None]:
360+
) -> BaseBackgroundCallbackManager:
367361
"""Set up the background callback and manage jobs."""
368362
callback_manager = background.get(
369363
"manager", kwargs.get("background_callback_manager", None)
@@ -379,7 +373,7 @@ def _get_callback_manager(
379373
" and store results on redis.\n"
380374
)
381375

382-
adapter = backends.request_adapter()
376+
adapter = backends.backend.request_adapter()
383377
old_job = adapter.args.getlist("oldJob") if hasattr(adapter.args, "getlist") else []
384378

385379
if old_job:
@@ -439,7 +433,7 @@ def _setup_background_callback(
439433

440434
def _progress_background_callback(response, callback_manager, background):
441435
progress_outputs = background.get("progress")
442-
adapter = backends.request_adapter()
436+
adapter = backends.backend.request_adapter()
443437
cache_key = adapter.args.get("cacheKey")
444438

445439
if progress_outputs:
@@ -457,7 +451,7 @@ def _update_background_callback(
457451
"""Set up the background callback and manage jobs."""
458452
callback_manager = _get_callback_manager(kwargs, background)
459453

460-
adapter = backends.request_adapter()
454+
adapter = backends.backend.request_adapter()
461455
cache_key = adapter.args.get("cacheKey") if adapter else None
462456
job_id = adapter.args.get("job") if adapter else None
463457

@@ -479,7 +473,7 @@ def _handle_rest_background_callback(
479473
multi,
480474
has_update=False,
481475
):
482-
adapter = backends.request_adapter()
476+
adapter = backends.backend.request_adapter()
483477
cache_key = adapter.args.get("cacheKey") if adapter else None
484478
job_id = adapter.args.get("job") if adapter else None
485479
# Must get job_running after get_result since get_results terminates it.
@@ -697,7 +691,7 @@ def add_context(*args, **kwargs):
697691
jsonResponse: Optional[str] = None
698692
try:
699693
if background is not None:
700-
adapter = backends.request_adapter()
694+
adapter = backends.backend.request_adapter()
701695
if not (adapter and adapter.args.get("cacheKey")):
702696
return _setup_background_callback(
703697
kwargs,
@@ -769,7 +763,7 @@ async def async_add_context(*args, **kwargs):
769763

770764
try:
771765
if background is not None:
772-
adapter = backends.request_adapter()
766+
adapter = backends.backend.request_adapter()
773767
if not (adapter and adapter.args.get("cacheKey")):
774768
return _setup_background_callback(
775769
kwargs,

dash/_validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,14 @@ def _valid(out):
590590
def check_async(use_async):
591591
if use_async is None:
592592
try:
593-
import asgiref # pylint: disable=unused-import, import-outside-toplevel # noqa
593+
import asgiref # type: ignore[import-not-found] # pylint: disable=unused-import, import-outside-toplevel # noqa
594594

595595
use_async = True
596596
except ImportError:
597597
pass
598598
elif use_async:
599599
try:
600-
import asgiref # pylint: disable=unused-import, import-outside-toplevel # noqa
600+
import asgiref # type: ignore[import-not-found] # pylint: disable=unused-import, import-outside-toplevel # noqa
601601
except ImportError as exc:
602602
raise Exception(
603603
"You are trying to use dash[async] without having installed the requirements please install via: `pip install dash[async]`"

dash/backends/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _is_flask_instance(obj):
4343
def _is_fastapi_instance(obj):
4444
try:
4545
# pylint: disable=import-outside-toplevel
46-
from fastapi import FastAPI
46+
from fastapi import FastAPI # type: ignore[import-not-found]
4747

4848
return isinstance(obj, FastAPI)
4949
except ImportError:
@@ -53,7 +53,7 @@ def _is_fastapi_instance(obj):
5353
def _is_quart_instance(obj):
5454
try:
5555
# pylint: disable=import-outside-toplevel
56-
from quart import Quart
56+
from quart import Quart # type: ignore[import-not-found]
5757

5858
return isinstance(obj, Quart)
5959
except ImportError:

dash/dash.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import traceback
2222

23-
from importlib_metadata import version as _get_distribution_version
24-
2523
from dash import dcc
2624
from dash import html
2725
from dash import dash_table
@@ -53,7 +51,6 @@
5351
convert_to_AttributeDict,
5452
gen_salt,
5553
hooks_to_js_object,
56-
parse_version,
5754
get_caller_name,
5855
get_root_path,
5956
)
@@ -1182,7 +1179,7 @@ def index(self, *_args, **_kwargs):
11821179
renderer = self._generate_renderer()
11831180
title = self.title
11841181
# Refactored: direct access to global request adapter
1185-
request = backends.request_adapter()
1182+
request = backends.backend.request_adapter()
11861183

11871184
if self.use_pages and self.config.include_pages_meta and request:
11881185
metas = _page_meta_tags(self, request) + metas
@@ -1398,7 +1395,7 @@ def _inputs_to_vals(self, inputs):
13981395
# pylint: disable=R0915
13991396
def _initialize_context(self, body):
14001397
"""Initialize the global context for the request."""
1401-
adapter = backends.request_adapter()
1398+
adapter = backends.backend.request_adapter()
14021399
g = AttributeDict({})
14031400
g.inputs_list = body.get("inputs", [])
14041401
g.states_list = body.get("state", [])
@@ -2445,6 +2442,7 @@ async def get_layouts():
24452442
]
24462443

24472444
layouts = await get_layouts()
2445+
# pylint: disable=not-callable
24482446
layouts += [self.layout() if callable(self.layout) else self.layout]
24492447
self.validation_layout = html.Div(layouts)
24502448
if _ID_CONTENT not in self.validation_layout:
@@ -2512,6 +2510,7 @@ def update(pathname_, search_, **states):
25122510
if not self.config.suppress_callback_exceptions:
25132511
layout = self.layout
25142512
if not isinstance(layout, list):
2513+
# pylint: disable=not-callable
25152514
layout = [self.layout() if callable(self.layout) else self.layout]
25162515
self.validation_layout = html.Div(
25172516
[

0 commit comments

Comments
 (0)