Skip to content

Commit db48c94

Browse files
hebaalazzehohmayr
andcommitted
Update packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/_compat.py.j2
Co-authored-by: ohmayr <omairnaveed@ymail.com>
1 parent 1df077f commit db48c94

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/_compat.py.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
{% block content %}
44

5-
"""A compatibility module for older versions of google-api-core."""
5+
6+
{% set has_auto_populated_fields = api.all_method_settings.values()|map(attribute="auto_populated_fields", default=[])|select|list %}
67
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17813):
78
Clean up this file/functions when the minimum supported version of
89
google-api-core has the functions in `_compat.py.j2`. #}
@@ -12,6 +13,7 @@ falling back to the local implementation if not present. #}
1213
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17883):
1314
Backfill compatibility functions being removed from the client layer. #}
1415

16+
{% if has_auto_populated_fields %}
1517
from typing import Union
1618
import uuid
1719

@@ -61,4 +63,5 @@ def setup_request_id(
6163
else:
6264
if not getattr(request, field_name, None):
6365
setattr(request, field_name, str(uuid.uuid4()))
66+
{% endif %}
6467
{% endblock %}

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_compat.py.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
{% block content %}
44

5+
{% set has_auto_populated_fields = api.all_method_settings.values()|map(attribute="auto_populated_fields", default=[])|select|list %}
56
"""Tests for the compatibility module for older versions of google-api-core."""
67
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17813):
78
Clean up this file/tests when the minimum supported version of
@@ -10,6 +11,7 @@ google-api-core has the functions in `_compat.py.j2`. #}
1011
Backfill compatibility functions tests being removed from the client layer. #}
1112

1213

14+
{% if has_auto_populated_fields %}
1315
import re
1416
import pytest
1517

@@ -96,4 +98,5 @@ def test_setup_request_id(request_obj, is_proto3_optional, expected):
9698
else:
9799
assert value == expected
98100

101+
{% endif %}
99102
{% endblock %}

0 commit comments

Comments
 (0)