Skip to content

Commit e67c36a

Browse files
committed
separate out context
1 parent 16160ad commit e67c36a

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

gapic/cli/generate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def generate(request: typing.BinaryIO, output: typing.BinaryIO) -> None:
6363
# to each template in the rendering step.
6464
api_schema = api.API.build(req.proto_file, opts=opts, package=package)
6565

66+
with generation_cache_context():
6667
# Translate into a protobuf CodeGeneratorResponse; this reads the
6768
# individual templates and renders them.
6869
# If there are issues, error out appropriately.

gapic/utils/cache.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,14 @@ def wrapper(self, *, collisions, **kwargs):
8888
if context_cache is None:
8989
return func(self, collisions=collisions, **kwargs)
9090

91-
col_key = frozenset(collisions) if collisions else None
92-
93-
# CRITICAL FIX: Include these flags in the key.
94-
# This prevents the "Summary" (skip_fields=True) from being returned
95-
# when the template asks for the "Full" (skip_fields=False) object.
96-
skip_key = kwargs.get('skip_fields', False)
97-
98-
visited = kwargs.get('visited_messages')
99-
vis_key = tuple(sorted(id(m) for m in visited)) if visited else None
100-
101-
key = (id(self), col_key, skip_key, vis_key)
91+
# 2. Create the cache key
92+
collisions_key = frozenset(collisions) if collisions else None
93+
key = (id(self), collisions_key)
10294

10395
# 3. Check Cache
10496
if key in context_cache:
10597
return context_cache[key]
10698

107-
keep_alive.append(self)
108-
10999
# 4. Execute the actual function
110100
# We ensure context_cache is passed down to the recursive calls
111101
result = func(self, collisions=collisions, **kwargs)

0 commit comments

Comments
 (0)