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

functions-framework breaks import paths for the google-cloud-functions SDK package #184

Open
jyork03 opened this issue Apr 29, 2022 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers P3

Comments

@jyork03
Copy link

jyork03 commented Apr 29, 2022

functions-framework is incompatible with the google-cloud-functions SDK package, unless google-cloud-functions is installed with a separate install command AFTER functions-framework is installed.

As I understand it, this is not possible to do within the context of Google Cloud Functions, where packages get installed automatically from the requirements.txt file.

The reason is that functions-framework overwrites several important files in google/cloud/functions_v1, google/cloud/functions, and google/cloud/functions_v1beta2 that are required to make the google-cloud-functions SDK package work as intended.

For example: functions-framework overwrites google/cloud/functions_v1/__init__.py upon install, which breaks the ability to import packages in the normal, documented ways.

Steps to reproduce:

  1. create a new python 3.9 environment:

  2. Run: pip install google-cloud-functions==1.6.0 functions-framework==3.0.0

  3. Then execute:

from google.cloud import functions_v1
functions_v1.CloudFunctionsServiceClient()

This will raise:
AttributeError: module 'google.cloud.functions_v1' has no attribute 'CloudFunctionsServiceClient'

Edit:
This means that none of the sample code in the docs will work, since they all rely on the imported members from google/cloud/functions_v1/__init__.py. Example below:
https://cloud.google.com/python/docs/reference/cloudfunctions/latest/google.cloud.functions_v1.services.cloud_functions_service.CloudFunctionsServiceClient#google_cloud_functions_v1_services_cloud_functions_service_CloudFunctionsServiceClient_create_function

@jyork03
Copy link
Author

jyork03 commented Apr 29, 2022

For anyone that might be stuck on this in the meantime, you can import the client and functions directly:

from google.cloud.functions_v1.services.cloud_functions_service import CloudFunctionsServiceClient
from google.cloud.functions_v1.types.functions import EventTrigger, CreateFunctionRequest, CloudFunction

@jyork03 jyork03 changed the title functions-framework breaks the google-cloud-functions SDK package functions-framework breaks import paths for the google-cloud-functions SDK package Apr 29, 2022
@josephlewis42 josephlewis42 added bug Something isn't working good first issue Good for newcomers labels Feb 24, 2023
@0x0elliot
Copy link

0x0elliot commented Mar 21, 2024

Here is how i quickly fixed this problem for myself (with no hassle), for anyone who finds this bug in the wild:

pip3 uninstall functions-framework
pip3 uninstall google-cloud-functions
pip3 install google-cloud-functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers P3
Projects
None yet
Development

No branches or pull requests

5 participants