Skip to content

Commit 1c4d199

Browse files
fix: preventing accessing predefined discovery URLs when override is provided (#1324)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-api-python-client/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [X] Ensure the tests and linter pass - [X] Code coverage does not decrease (if any source code was changed) - [X] Appropriate docs were updated (if necessary) Fixes #1322 🦕
1 parent 9e2cde2 commit 1c4d199

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

googleapiclient/discovery.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ def build(
274274
else:
275275
static_discovery = False
276276

277-
if discoveryServiceUrl is None:
278-
discoveryServiceUrl = DISCOVERY_URI
279-
280277
if http is None:
281278
discovery_http = build_http()
282279
else:
@@ -343,14 +340,16 @@ def _discovery_service_uri_options(discoveryServiceUrl, version):
343340
A list of URIs to be tried for the Service Discovery, in order.
344341
"""
345342

346-
urls = [discoveryServiceUrl, V2_DISCOVERY_URI]
347-
# V1 Discovery won't work if the requested version is None
348-
if discoveryServiceUrl == V1_DISCOVERY_URI and version is None:
343+
if discoveryServiceUrl is not None:
344+
return [discoveryServiceUrl]
345+
if version is None:
346+
# V1 Discovery won't work if the requested version is None
349347
logger.warning(
350348
"Discovery V1 does not support empty versions. Defaulting to V2..."
351349
)
352-
urls.pop(0)
353-
return list(OrderedDict.fromkeys(urls))
350+
return [V2_DISCOVERY_URI]
351+
else:
352+
return [DISCOVERY_URI, V2_DISCOVERY_URI]
354353

355354

356355
def _retrieve_discovery_doc(

0 commit comments

Comments
 (0)