From 1de9836604aa6a21ebf758d06ab6cafd37dce13f Mon Sep 17 00:00:00 2001 From: Marty Woodlee Date: Thu, 11 Nov 2021 17:10:28 -0600 Subject: [PATCH] Prevent errors when field truncation is configured for a nullable string field --- cdc_kafka/tracked_tables.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdc_kafka/tracked_tables.py b/cdc_kafka/tracked_tables.py index 7d7cfb4..e6def92 100644 --- a/cdc_kafka/tracked_tables.py +++ b/cdc_kafka/tracked_tables.py @@ -35,9 +35,10 @@ def __init__(self, name: str, sql_type_name: str, change_table_ordinal: int, pri f'string field (SQL type is {sql_type_name}).') orig_transform = self.transform_fn if orig_transform is not None: - self.transform_fn = lambda x: orig_transform(x)[:int(truncate_after)] + # TODO: this prevents orig_transform from ever receiving a None argument; is that okay?? + self.transform_fn = lambda x: orig_transform(x)[:int(truncate_after)] if x is not None else x else: - self.transform_fn = lambda x: x[:int(truncate_after)] + self.transform_fn = lambda x: x[:int(truncate_after)] if x is not None else x class TrackedTable(object):