Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Published package is missing discovery files in discovery_cache #1214

Closed
busunkim96 opened this issue Mar 4, 2021 · 8 comments · Fixed by #1216 or #1221
Closed

Published package is missing discovery files in discovery_cache #1214

busunkim96 opened this issue Mar 4, 2021 · 8 comments · Fixed by #1216 or #1221
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@busunkim96
Copy link
Contributor

Many thanks to the @wyk9787 for noticing this and reaching out.

All calls to discovery.build() using 2.0.0 fail with "unknown api name or version".

from googleapiclient import discovery

client = discovery.build("cloudprofiler", "v2")

This is because the published package has no discovery_cache/documents directory.

  1. python3 -m venv env
  2. source env/bin/activate
  3. python3 -m pip install google-api-python-client
  4. ls env/lib/python*/site-packages/googleapiclient/discovery_cache
busunkim@busunkim:~/github$ ls env/lib/python*/site-packages/googleapiclient/discovery_cache
appengine_memcache.py  base.py  file_cache.py  __init__.py  __pycache__
@busunkim96 busunkim96 added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Mar 4, 2021
gcf-merge-on-green bot pushed a commit that referenced this issue Mar 4, 2021
Fixes #1214 

The [MANIFEST.in](https://packaging.python.org/guides/using-manifest-in/) controls which files are included in the published package.

You can verify that this fixes the problem (missing discovery docs leading to failing `discovery.build()` calls) by building the package and installing the library from the tarfile.


- `python3 -m venv env`
- `source env/bin/activate`
- `python3 -m setup.py sdist`
- `python3 -m pip install dist/google-api-python-client-2.0.0.tar.gz`


```
(env) busunkim@busunkim:~/github/google-api-python-client$ python3
Python 3.6.9 (default, Feb 24 2020, 21:10:07) 
[GCC 9.2.1 20190909] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import googleapiclient
>>> from googleapiclient import discovery
>>> client = discovery.build("cloudprofiler", "v2")
>>> 
```
@parthea parthea reopened this Mar 4, 2021
@parthea
Copy link
Contributor

parthea commented Mar 4, 2021

Version 2.0.1 also has the same issue. The issue is resolved by changing this line from

    package_data={},

to

package_data={"googleapiclient": ["discovery_cache/documents/*.json"]},

gcf-merge-on-green bot pushed a commit that referenced this issue Mar 4, 2021
Fixes #1214  🦕

I was able to re-create the issue by using the following steps.
1) Create a clean `pyenv` environment
2) Download google-api-python-client-2.0.1 from PyPi [here](https://files.pythonhosted.org/packages/dc/67/a228c05a28288fdfde6e8c1a27a62e10ee265664c0f1d59070e6e0dc6242/google-api-python-client-2.0.1.tar.gz) and unzip it
3) Install it using `pip install <Unzipped Directory>`
4) Confirm `discovery.build()` fails on any call

To Verify the fix, repeat the steps above, but apply the update in this PR prior to installing the library.
@chensun
Copy link
Member

chensun commented Mar 5, 2021

@parthea, the issue still exists in 2.0.2 for me.

!pip freeze | grep google-api-python-client
google-api-python-client==2.0.2

and I got the same error:

/opt/conda/lib/python3.7/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

/opt/conda/lib/python3.7/site-packages/googleapiclient/discovery.py in build(serviceName, version, http, discoveryServiceUrl, developerKey, model, requestBuilder, credentials, cache_discovery, cache, client_options, adc_cert_path, adc_key_path, num_retries, static_discovery)
    280                 developerKey,
    281                 num_retries=num_retries,
--> 282                 static_discovery=static_discovery,
    283             )
    284             service = build_from_document(

/opt/conda/lib/python3.7/site-packages/googleapiclient/discovery.py in _retrieve_discovery_doc(url, http, cache_discovery, serviceName, version, cache, developerKey, num_retries, static_discovery)
    385             return content
    386         else:
--> 387             raise UnknownApiNameOrVersion("name: %s  version: %s" % (serviceName, version))
    388 
    389     actual_url = url

After I downgraded to 1.12.8, the error is gone.

@chensun
Copy link
Member

chensun commented Mar 5, 2021

Okay, I just found out: #1225 (comment) and #1225 (comment)

Our API is indeed private at this point.

@Ark-kun
Copy link

Ark-kun commented Mar 8, 2021

Okay, I just found out: #1225 (comment) and #1225 (comment)

Our API is indeed private at this point.

@chensun
See the comment there: #1225 (comment)

@chensun
Copy link
Member

chensun commented Mar 8, 2021

@chensun
See the comment there: #1225 (comment)

Yes, I saw that, it's in the 2nd comments I referenced above.

In the original comment, it says:

This results in behavior equivalent to 1.x of this library.

So my thinking was why bother upgrading to 2.x, yet changing the code to make it behave just like 1.x. There's no known features from 2.x that we want to take advantage of at this moment. So why not just use 1.x until our API becomes public, by that time we can lift the version restriction without changing the code twice. WDYT? @Ark-kun

@parthea parthea reopened this Mar 9, 2021
@parthea
Copy link
Contributor

parthea commented Mar 9, 2021

I'm re-opening this issue to propose a change to improve the behaviour in version 2.0.2. By design, google-api-python-client version 2.0.2 will fail if the library doesn't have the service definition and static_discovery=True, however we may be able to make some improvements to the default value of static_discovery based on the arguments provided to discovery.build().

The following sample code from #935 will result in a breaking change when upgrading to 2.0.2 if the discovery document is not public because the user has not specified static_discovery, and the default value is True.

my_client = googleapiclient.discovery.build(
    'someapi',
    'v1alpha1',
    discoveryServiceUrl=apiclient.discovery.V2_DISCOVERY_URI + '&labels=TRUSTED_TESTER_FEATURE',
    developerKey=my_developer_key)

I'd like to propose to make the above code work. Looking at the above snippet, one can assume that the user wants to retrieve discovery documents dynamically since they have provided the discoveryServiceUrl argument.

If a user specifies the discoveryServiceUrl argument in discovery.build() but does not specify the static_discovery argument, we should assume that the user wants to retrieve the discovery document from the internet. In that case, the default value for static_discovery would be changed to False.

If we proceed, the docs would be updated to explain the new behaviour.

@parthea parthea self-assigned this Mar 9, 2021
@parthea
Copy link
Contributor

parthea commented Mar 9, 2021

cc @busunkim96 for review

@parthea
Copy link
Contributor

parthea commented Mar 9, 2021

Closing this off, as the discussion is already in #1225 and we are going to proceed with this change.

@parthea parthea closed this as completed Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
4 participants