Skip to content

Commit edf4037

Browse files
committed
fix: handle text list index normalization
1 parent a84724f commit edf4037

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

core/converter.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _normalize_number_index_value(self, value: Any) -> Optional[str]:
162162
return str(number)
163163

164164
def _normalize_timestamp_index_value(self, value: Any) -> Optional[str]:
165-
"""规范化日期索引值为飞书日期字段使用的毫秒时间戳。"""
165+
"""规范化日期索引值,统一为按天比较的 ISO 日期字符串。"""
166166
if self._is_empty_value(value):
167167
return None
168168

@@ -258,7 +258,17 @@ def _normalize_index_value(
258258
if field_type == 1 or all(
259259
isinstance(item, dict) and "text" in item for item in values
260260
):
261-
return "".join(str(item.get("text", "")) for item in values)
261+
text_parts = []
262+
for item in values:
263+
if isinstance(item, dict) and "text" in item:
264+
text_parts.append(str(item.get("text", "")))
265+
else:
266+
item_value = self._normalize_index_value(item)
267+
if item_value is not None:
268+
text_parts.append(item_value)
269+
if not text_parts:
270+
return None
271+
return "".join(text_parts)
262272

263273
normalized_items = [
264274
self._normalize_index_value(item, field_type) for item in values

tests/test_converter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ def test_get_index_value_hash_rich_text_matches_plain_text(self):
169169

170170
assert plain_hash == rich_text_hash
171171

172+
def test_get_index_value_hash_text_list_matches_plain_text(self):
173+
"""测试文本字段中 list[str] 与普通文本生成相同索引哈希"""
174+
converter = DataConverter(TargetType.BITABLE)
175+
plain_row = pd.Series({"ID": "AB"})
176+
text_list_row = pd.Series({"ID": ["A", "B"]})
177+
178+
plain_hash = converter.get_index_value_hash(plain_row, "ID", {"ID": 1})
179+
text_list_hash = converter.get_index_value_hash(text_list_row, "ID", {"ID": 1})
180+
181+
assert plain_hash == text_list_hash
182+
172183
def test_get_index_value_hash_date_string_matches_timestamp(self):
173184
"""测试本地日期字符串和飞书日期时间戳生成相同索引哈希"""
174185
converter = DataConverter(TargetType.BITABLE)

0 commit comments

Comments
 (0)