Skip to content

Commit 26b657d

Browse files
committed
Fix positional-args bug in discover_api_client → handle_api_client_discovery
When discover_api_client is called with positional next_args (e.g. ``self.discover_api_client(self._apply_active_connection, current_connection)`` from activate_connection_configuration's cold-cache path), the cached NetworkResponse was being silently mis-slotted into the response-less next_() callable, manifesting as AttributeError: 'NetworkResponse' object has no attribute 'base_url' inside _apply_active_connection. The cause: ``finished`` emits one positional NetworkResponse, and ``partial(handler, next_, *next_args)`` *appends* that NetworkResponse to the end of the bound args. The handler's signature was handle_api_client_discovery(next_, response, *next_args, **next_kwargs) so when next_args was non-empty the call became ``handle_api_client_discovery(next_, current_connection, NetworkResponse)`` — current_connection in the response slot, the actual response in *next_args. Then ``next_(*next_args, **next_kwargs)`` invoked self._apply_active_connection(NetworkResponse) instead of self._apply_active_connection(current_connection). The contract was already wrong in the legacy code (same partial/append shape with ``task_result: bool`` in place of ``response``), but every caller used kwargs only, so it never tripped. Phase 3 introduced the positional-arg call site and exposed it; Phase 6 made it the default path on cold-cache connection switches. Fix: * Replace the partial with a lambda that explicitly discards the NetworkResponse and forwards next_ / next_args / next_kwargs as-is. * Drop the unused ``response`` parameter from handle_api_client_discovery — the handler doesn't read the response body; the api-support cache populated by probe_api_client's own finished slot is the source of truth by the time the handler runs. Also drops the now-unused ``NetworkResponse`` import.
1 parent a10894a commit 26b657d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/qgis_geonode/gui/geonode_data_source_widget.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ..apiclient.models import ApiClientCapability, IsoTopicCategory
2626
from ..gui.connection_dialog import ConnectionDialog
2727
from ..gui.search_result_widget import SearchResultWidget
28-
from ..httpclient import NetworkError, NetworkResponse, Request
28+
from ..httpclient import NetworkError, Request
2929
from ..utils import (
3030
tr,
3131
)
@@ -473,14 +473,24 @@ def discover_api_client(self, next_: typing.Callable, *next_args, **next_kwargs)
473473
timeout_ms=current_connection.network_requests_timeout,
474474
parent=self,
475475
)
476+
# A lambda — not partial — is required here. ``finished`` emits one
477+
# positional NetworkResponse; ``partial(handler, next_, *next_args)``
478+
# would *append* that NetworkResponse after the bound args, which
479+
# quietly mis-slots ``response`` as ``next_args[0]`` whenever the
480+
# caller passes any positional next_args (e.g.
481+
# ``discover_api_client(self._apply_active_connection,
482+
# current_connection)``). The lambda explicitly discards the
483+
# NetworkResponse — handle_api_client_discovery doesn't need it; the
484+
# api-support cache is the source of truth by the time it runs.
476485
self.discovery_task.finished.connect(
477-
partial(self.handle_api_client_discovery, next_, *next_args, **next_kwargs)
486+
lambda _response: self.handle_api_client_discovery(
487+
next_, *next_args, **next_kwargs
488+
)
478489
)
479490

480491
def handle_api_client_discovery(
481492
self,
482493
next_: typing.Callable,
483-
response: NetworkResponse,
484494
*next_args,
485495
**next_kwargs,
486496
):

0 commit comments

Comments
 (0)