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

Avoid generating modules that conflict with builtin modules #2269

Open
parthea opened this issue Dec 3, 2024 · 0 comments
Open

Avoid generating modules that conflict with builtin modules #2269

parthea opened this issue Dec 3, 2024 · 0 comments
Assignees
Labels
next major: breaking change this is a change that we should wait to bundle into the next major version priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@parthea
Copy link
Contributor

parthea commented Dec 3, 2024

A file logging.py exists in the generated client for google-cloud-logging in the directory google/cloud/logging_v2/types here.

It's not ideal to import the client using the statement from google.cloud.logging_v2.types import logging like we do here :

The reason is that logging is also a built-in Python3 module, and from google.cloud.logging_v2.types import logging will clobber the built-in module logging.

See the error in https://github.com/googleapis/gapic-generator-python/actions/runs/12129001516/job/33816582330

___ ERROR collecting tests/unit/gapic/logging_v2/test_metrics_service_v2.py ____
tests/unit/gapic/logging_v2/test_metrics_service_v2.py:51: in <module>
    from google.cloud.logging_v2.services.metrics_service_v2 import MetricsServiceV2AsyncClient
google/cloud/logging_v2/services/metrics_service_v2/__init__.py:16: in <module>
    from .client import MetricsServiceV2Client
google/cloud/logging_v2/services/metrics_service_v2/client.py:23: in <module>
    from google.cloud.logging_v2 import gapic_version as package_version
google/cloud/logging_v2/__init__.py:23: in <module>
    from .services.logging_service_v2 import LoggingServiceV2Client
google/cloud/logging_v2/services/logging_service_v2/__init__.py:17: in <module>
    from .async_client import LoggingServiceV2AsyncClient
google/cloud/logging_v2/services/logging_service_v2/async_client.py:51: in <module>
    _LOGGER = logging.getLogger(__name__)
E   AttributeError: module 'google.cloud.logging_v2.types.logging' has no attribute 'getLogger'

The fix is to ensure that we don't generate files which conflict with built-in modules. As an example, instead of logging.py, we could have types_logging.py

@parthea parthea added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. next major: breaking change this is a change that we should wait to bundle into the next major version labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next major: breaking change this is a change that we should wait to bundle into the next major version priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

1 participant