Skip to content

Commit 5573135

Browse files
authored
Avoid overwriting '__module__' of messages from shared modules. (#5364)
Note that we *are* still overwriting it for messages from modules defined within the current package. See #4715.
1 parent 40d6539 commit 5573135

File tree

1 file changed

+38
-26
lines changed
  • packages/google-cloud-logging/google/cloud/logging_v2

1 file changed

+38
-26
lines changed

packages/google-cloud-logging/google/cloud/logging_v2/types.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@
1515
from __future__ import absolute_import
1616
import sys
1717

18-
from google.api_core.protobuf_helpers import get_messages
19-
2018
from google.api import distribution_pb2
2119
from google.api import http_pb2
2220
from google.api import label_pb2
2321
from google.api import metric_pb2
2422
from google.api import monitored_resource_pb2
25-
from google.cloud.logging_v2.proto import log_entry_pb2
26-
from google.cloud.logging_v2.proto import logging_config_pb2
27-
from google.cloud.logging_v2.proto import logging_metrics_pb2
28-
from google.cloud.logging_v2.proto import logging_pb2
2923
from google.logging.type import http_request_pb2
3024
from google.protobuf import any_pb2
3125
from google.protobuf import descriptor_pb2
@@ -36,27 +30,45 @@
3630
from google.protobuf import timestamp_pb2
3731
from google.rpc import status_pb2
3832

33+
from google.api_core.protobuf_helpers import get_messages
34+
from google.cloud.logging_v2.proto import log_entry_pb2
35+
from google.cloud.logging_v2.proto import logging_config_pb2
36+
from google.cloud.logging_v2.proto import logging_metrics_pb2
37+
from google.cloud.logging_v2.proto import logging_pb2
38+
39+
40+
_shared_modules = [
41+
distribution_pb2,
42+
http_pb2,
43+
label_pb2,
44+
metric_pb2,
45+
monitored_resource_pb2,
46+
http_request_pb2,
47+
any_pb2,
48+
descriptor_pb2,
49+
duration_pb2,
50+
empty_pb2,
51+
field_mask_pb2,
52+
struct_pb2,
53+
timestamp_pb2,
54+
status_pb2,
55+
]
56+
57+
_local_modules = [
58+
log_entry_pb2,
59+
logging_config_pb2,
60+
logging_metrics_pb2,
61+
logging_pb2,
62+
]
63+
3964
names = []
40-
for module in (
41-
distribution_pb2,
42-
http_pb2,
43-
label_pb2,
44-
metric_pb2,
45-
monitored_resource_pb2,
46-
log_entry_pb2,
47-
logging_config_pb2,
48-
logging_metrics_pb2,
49-
logging_pb2,
50-
http_request_pb2,
51-
any_pb2,
52-
descriptor_pb2,
53-
duration_pb2,
54-
empty_pb2,
55-
field_mask_pb2,
56-
struct_pb2,
57-
timestamp_pb2,
58-
status_pb2,
59-
):
65+
66+
for module in _shared_modules:
67+
for name, message in get_messages(module).items():
68+
setattr(sys.modules[__name__], name, message)
69+
names.append(name)
70+
71+
for module in _local_modules:
6072
for name, message in get_messages(module).items():
6173
message.__module__ = 'google.cloud.logging_v2.types'
6274
setattr(sys.modules[__name__], name, message)

0 commit comments

Comments
 (0)