Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 6945872

Browse files
authored
Merge pull request #24 from supabase-community/sourcery/pull-23
Bug fixes and parsing timestamptz (Sourcery refactored)
2 parents ac90f6c + 05920c6 commit 6945872

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

realtime/transformers.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242

4343

4444
def convert_change_data(columns, records, options={}):
45-
result = {}
4645
skip_types = options.get("skip_types") if options.get(
4746
"skip_types") == "undefined" else []
48-
for key in records.keys():
49-
result[key] = convert_column(key, columns, records, skip_types)
50-
return result
47+
return {
48+
key: convert_column(key, columns, records, skip_types)
49+
for key in records.keys()
50+
}
5151

5252

5353
def convert_column(column_name, columns, records, skip_types):
@@ -60,11 +60,11 @@ def convert_column(column_name, columns, records, skip_types):
6060

6161
def convert_cell(_type: str, string_value: str):
6262
try:
63-
if string_value == None:
63+
if string_value is None:
6464
return None
6565
# If data type is an array
6666
if _type[0] == "_":
67-
array_value = _type[1, len(_type)]
67+
array_value = _type[1:len(_type)]
6868
return to_array(string_value, array_value)
6969
# If it's not null then we need to convert it to the correct type
7070
if _type == abstime:
@@ -87,9 +87,9 @@ def convert_cell(_type: str, string_value: str):
8787
elif _type == int4range:
8888
return to_int_range(string_value)
8989
elif _type == int8:
90-
return to_int_range(string_value)
91-
elif _type == int8range:
9290
return to_int(string_value)
91+
elif _type == int8range:
92+
return to_int_range(string_value)
9393
elif _type == _json:
9494
return to_json(string_value)
9595
elif _type == jsonb:
@@ -111,11 +111,9 @@ def convert_cell(_type: str, string_value: str):
111111
string_value
112112
) # Format to be consistent with PostgREST
113113
elif _type == timestamptz:
114-
# To allow users to cast it based on Timezone
115-
return noop(string_value)
114+
return parse(string_value)
116115
elif _type == timetz:
117-
# To allow users to cast it based on Timezone
118-
return noop(string_value)
116+
return parse(string_value)
119117
elif _type == tsrange:
120118
return to_date_range(string_value)
121119
elif _type == tstzrange:
@@ -187,8 +185,7 @@ def to_array(string_value: str, type: str):
187185
# if string is empty (meaning the array was empty), an empty array will be immediately returned
188186
string_array = string_enriched.split(
189187
",") if len(string_enriched) > 0 else []
190-
array = list(map(lambda string: convert_cell(type, string), string_array))
191-
return array
188+
return list(map(lambda string: convert_cell(type, string), string_array))
192189

193190

194191
"""

0 commit comments

Comments
 (0)