File tree Expand file tree Collapse file tree
packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828{% if method_settings is not none %}
2929{% for auto_populated_field in method_settings .auto_populated_fields %}
3030 {% set is_proto 3_optional = method .input .fields [auto_populated_field ].proto 3_optional %}
31- {% if is_async %}
32- self._client._setup_request_id(request, '{{ auto_populated_field }}', {{ is_proto3_optional }})
33- {% else %}
34- self._setup_request_id(request, '{{ auto_populated_field }}', {{ is_proto3_optional }})
35- {% endif %}
31+ setup_request_id(request, '{{ auto_populated_field }}', {{ is_proto3_optional }})
3632{% endfor %}
3733{% endif %} {# if method_settings is not none #}
3834{% endwith %} {# method_settings #}
Original file line number Diff line number Diff line change 44{% import "%namespace/%name_%version/%sub/services/%service/_client_macros.j2" as macros %}
55{% import "%namespace/%name_%version/%sub/services/%service/_shared_macros.j2" as shared_macros %}
66
7+ {% set has_auto_populated_fields = namespace (value =false ) %}
8+ {% for method in service .methods .values () %}
9+ {% set method_settings = api .all_method_settings .get (method .meta .address .proto ) %}
10+ {% if method_settings and method_settings .auto_populated_fields %}
11+ {% set has_auto_populated_fields .value = true %}
12+ {% endif %}
13+ {% endfor %}
14+
715import logging as std_logging
816from collections import OrderedDict
917import re
@@ -18,6 +26,9 @@ from {{package_path}} import gapic_version as package_version
1826from google.api_core.client_options import ClientOptions
1927from google.api_core import exceptions as core_exceptions
2028from google.api_core import gapic_v1
29+ {% if has_auto_populated_fields .value %}
30+ from google.api_core.gapic_v1.request import setup_request_id
31+ {% endif %}
2132from google.api_core import retry_async as retries
2233from google.auth import credentials as ga_credentials # type: ignore
2334from google.oauth2 import service_account # type: ignore
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ from google.api_core import extended_operation
3636{% endif %}
3737from google.api_core import gapic_v1
3838{% if has_auto_populated_fields .value %}
39- from google.api_core.gapic_v1 import request
39+ from google.api_core.gapic_v1.request import setup_request_id
4040{% endif %}
4141from google.api_core import retry as retries
4242from google.auth import credentials as ga_credentials # type: ignore
@@ -461,18 +461,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
461461 # NOTE (b/349488459): universe validation is disabled until further notice.
462462 return True
463463
464- {% if has_auto_populated_fields .value %}
465- @staticmethod
466- def _setup_request_id(request, field_name: str, is_proto3_optional: bool):
467- """Populate a UUID4 field in the request if it is not already set.
468464
469- Args:
470- request (Union[google.protobuf.message.Message, dict]): The request object.
471- field_name (str): The name of the field to populate.
472- is_proto3_optional (bool): Whether the field is proto3 optional.
473- """
474- request.setup_request_id(request, field_name, is_proto3_optional)
475- {% endif %}
476465
477466 def _add_cred_info_for_auth_errors(
478467 self,
You can’t perform that action at this time.
0 commit comments