Skip to content
Permalink
Browse files
fix: Change default of static_discovery when discoveryServiceUrl
…set (#1261)

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 #1225 🦕
  • Loading branch information
parthea committed Mar 19, 2021
1 parent d1a255f commit 3b4f2e243709132b5ca41a3c23853d5067dfb0ab
Showing with 28 additions and 9 deletions.
  1. +4 −1 UPGRADING.md
  2. +21 −3 googleapiclient/discovery.py
  3. +3 −5 tests/test_discovery.py
@@ -28,7 +28,10 @@ discovery document is private and it will not be shipped with the library.
Only discovery documents listed in [this public directory](https://www.googleapis.com/discovery/v1/apis/)
are included in the library. Users of private APIs should set the
`static_discovery` argument of `discovery.build()` to `False` to continue to
retrieve the service definition from the internet.
retrieve the service definition from the internet. As of version 2.1.0,
for backwards compatability with version 1.x, if `static_discovery` is not
specified, the default value for `static_discovery` will be `True` when
the `discoveryServiceUrl` argument of `discovery.build()` is provided.

If you experience issues or have questions, please file an [issue](https://github.com/googleapis/google-api-python-client/issues).

@@ -182,7 +182,7 @@ def build(
serviceName,
version,
http=None,
discoveryServiceUrl=DISCOVERY_URI,
discoveryServiceUrl=None,
developerKey=None,
model=None,
requestBuilder=HttpRequest,
@@ -193,7 +193,7 @@ def build(
adc_cert_path=None,
adc_key_path=None,
num_retries=1,
static_discovery=True,
static_discovery=None,
):
"""Construct a Resource for interacting with an API.
@@ -248,7 +248,10 @@ def build(
num_retries: Integer, number of times to retry discovery with
randomized exponential backoff in case of intermittent/connection issues.
static_discovery: Boolean, whether or not to use the static discovery docs
included in the library.
included in the library. The default value for `static_discovery` depends
on the value of `discoveryServiceUrl`. `static_discovery` will default to
`True` when `discoveryServiceUrl` is also not provided, otherwise it will
default to `False`.
Returns:
A Resource object with methods for interacting with the service.
@@ -259,6 +262,21 @@ def build(
"""
params = {"api": serviceName, "apiVersion": version}

# The default value for `static_discovery` depends on the value of
# `discoveryServiceUrl`. `static_discovery` will default to `True` when
# `discoveryServiceUrl` is also not provided, otherwise it will default to
# `False`. This is added for backwards compatability with
# google-api-python-client 1.x which does not support the `static_discovery`
# parameter.
if static_discovery is None:
if discoveryServiceUrl is None:
static_discovery = True
else:
static_discovery = False

if discoveryServiceUrl is None:
discoveryServiceUrl = DISCOVERY_URI

if http is None:
discovery_http = build_http()
else:
@@ -592,7 +592,7 @@ def test_building_with_context_manager(self):

def test_resource_close(self):
discovery = read_datafile("plus.json")

with mock.patch("httplib2.Http", autospec=True) as httplib2_http:
http = httplib2_http()
plus = build_from_document(
@@ -927,8 +927,7 @@ def test_userip_is_added_to_discovery_uri(self):
"v1",
http=http,
developerKey=None,
discoveryServiceUrl="http://example.com",
static_discovery=False,
discoveryServiceUrl="http://example.com"
)
self.fail("Should have raised an exception.")
except HttpError as e:
@@ -946,8 +945,7 @@ def test_userip_missing_is_not_added_to_discovery_uri(self):
"v1",
http=http,
developerKey=None,
discoveryServiceUrl="http://example.com",
static_discovery=False,
discoveryServiceUrl="http://example.com"
)
self.fail("Should have raised an exception.")
except HttpError as e:

0 comments on commit 3b4f2e2

Please sign in to comment.