Skip to content

Commit 69f022f

Browse files
committed
[Python] Fix AttributeError in ExternalTransform.expand by using get_type_hints() (Fixes #37289)
1 parent 4dcc27d commit 69f022f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

sdks/python/apache_beam/transforms/external.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,17 @@ def expand(self, pvalueish: pvalue.PCollection) -> pvalue.PCollection:
805805
urn=common_urns.primitives.IMPULSE.urn),
806806
outputs={'out': transform_proto.inputs[tag]}))
807807
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]:
808+
# Retrieve type hints and store them in variables to avoid duplicate calls and AttributeError
809+
hints = self.get_type_hints()
810+
output_coders = None
811+
if hints.output_types:
812+
if hints.output_types[0]:
813+
output_coders = dict((str(k), context.coder_id_from_element_type(v))
814+
for (k, v) in enumerate(hints.output_types[0]))
815+
elif hints.output_types[1]:
814816
output_coders = {
815817
k: context.coder_id_from_element_type(v)
816-
for (k, v) in self._type_hints.output_types[1].items()
818+
for (k, v) in hints.output_types[1].items()
817819
}
818820
components = context.to_runner_api()
819821
request = beam_expansion_api_pb2.ExpansionRequest(

0 commit comments

Comments
 (0)