Skip to content

Commit 68e0d66

Browse files
authored
[Python] Fix AttributeError in ExternalTransform.expand by using get_type_hints() (#37299)
* [Python] Fix AttributeError in ExternalTransform.expand by using get_type_hints() (Fixes #37289) * Fix lint: wrap long comment at line 808 * Fix yapf formatting and ignore local venv
1 parent ebcf5ab commit 68e0d66

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,4 @@ playground/cloudfunction.zip
154154
# Ignore .test-infra/metrics/github_runs_prefetcher/code.zip
155155
# as its generated with terraform
156156
.test-infra/metrics/sync/github/github_runs_prefetcher/code.zip
157+
.venv/

sdks/python/apache_beam/transforms/external.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -804,16 +804,19 @@ def expand(self, pvalueish: pvalue.PCollection) -> pvalue.PCollection:
804804
spec=beam_runner_api_pb2.FunctionSpec(
805805
urn=common_urns.primitives.IMPULSE.urn),
806806
outputs={'out': transform_proto.inputs[tag]}))
807+
808+
# Retrieve type hints and store them in variables
809+
# to avoid duplicate calls and AttributeError
810+
hints = self.get_type_hints()
807811
output_coders = None
808-
if self._type_hints.output_types:
809-
if self._type_hints.output_types[0]:
810-
output_coders = dict(
811-
(str(k), context.coder_id_from_element_type(v))
812-
for (k, v) in enumerate(self._type_hints.output_types[0]))
813-
elif self._type_hints.output_types[1]:
812+
if hints.output_types:
813+
if hints.output_types[0]:
814+
output_coders = dict((str(k), context.coder_id_from_element_type(v))
815+
for (k, v) in enumerate(hints.output_types[0]))
816+
elif hints.output_types[1]:
814817
output_coders = {
815818
k: context.coder_id_from_element_type(v)
816-
for (k, v) in self._type_hints.output_types[1].items()
819+
for (k, v) in hints.output_types[1].items()
817820
}
818821
components = context.to_runner_api()
819822
request = beam_expansion_api_pb2.ExpansionRequest(

0 commit comments

Comments
 (0)