From 18f1ebdaf02db94f9f0cc0d78d91a14d0c7dd910 Mon Sep 17 00:00:00 2001 From: Iakov Gan Date: Thu, 26 Dec 2024 18:22:09 +0100 Subject: [PATCH] allow resource_tags to be unicode --- cid/helpers/cur_proxy.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cid/helpers/cur_proxy.py b/cid/helpers/cur_proxy.py index 160333d9..aac4949b 100644 --- a/cid/helpers/cur_proxy.py +++ b/cid/helpers/cur_proxy.py @@ -532,11 +532,13 @@ def get_sql_expression(self, field, field_type): else: raise NotImplementedError(f'CUR1 field {field} has no known equivalent') if self.current_cur_version.startswith('2') and self.target_cur_version.startswith('1'): - if field.startswith('resource_tags_'): - return f"resource_tags['{field[len('resource_tags_'):]}']" - if field.startswith('cost_category_'): - return f"cost_category['{field[len('cost_category_'):]}']" - return cur1to2_mapping.get(field, field) + for tag_type in 'resource_tags', 'cost_category': + if field.startswith(tag_type + '_'): + short_field_name = field[len(tag_type + '_'):] + if short_field_name.encode('unicode-escape').decode('ascii') != short_field_name: + # name contains unicode characters that must be escaped + short_field_name = f'"{short_field_name}"' + return f"{tag_type}['{short_field_name}']" def column_surely_exist(self, field_to_expose):