Spaces:
Runtime error
Runtime error
Add detailed trade_date handling and error logging
Browse files- apps/api/routers/trade_hf.py +32 -23
apps/api/routers/trade_hf.py
CHANGED
|
@@ -74,29 +74,38 @@ async def search_trade_records(
|
|
| 74 |
records = result.scalars().all()
|
| 75 |
|
| 76 |
# 转换为响应格式
|
| 77 |
-
items = [
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
return PaginatedResponse(
|
| 102 |
items=items,
|
|
|
|
| 74 |
records = result.scalars().all()
|
| 75 |
|
| 76 |
# 转换为响应格式
|
| 77 |
+
items = []
|
| 78 |
+
for r in records:
|
| 79 |
+
try:
|
| 80 |
+
# 处理trade_date:如果是空字符串或None,使用默认日期
|
| 81 |
+
if not r.trade_date or (isinstance(r.trade_date, str) and r.trade_date.strip() == ''):
|
| 82 |
+
trade_date = datetime(2020, 1, 1)
|
| 83 |
+
else:
|
| 84 |
+
trade_date = r.trade_date
|
| 85 |
+
|
| 86 |
+
items.append(TradeRecordResponse(
|
| 87 |
+
record_id=r.record_id,
|
| 88 |
+
source_record_id=r.source_record_id,
|
| 89 |
+
source_country=r.source_country,
|
| 90 |
+
trade_direction=r.trade_direction,
|
| 91 |
+
trade_date=trade_date,
|
| 92 |
+
importer_name=r.importer_name or "",
|
| 93 |
+
exporter_name=r.exporter_name or "",
|
| 94 |
+
hs_code=r.hs_code or "",
|
| 95 |
+
product_name=r.product_name or "",
|
| 96 |
+
amount=r.amount,
|
| 97 |
+
currency=r.currency or "",
|
| 98 |
+
weight=r.weight,
|
| 99 |
+
weight_unit=r.weight_unit or "",
|
| 100 |
+
origin_country=r.origin_country or "",
|
| 101 |
+
destination_country=r.destination_country or "",
|
| 102 |
+
departure_port=r.departure_port or "",
|
| 103 |
+
arrival_port=r.arrival_port or "",
|
| 104 |
+
transport_mode=r.transport_mode or ""
|
| 105 |
+
))
|
| 106 |
+
except Exception as e:
|
| 107 |
+
print(f"Error processing record {r.record_id}: trade_date={repr(r.trade_date)}, error={e}")
|
| 108 |
+
raise
|
| 109 |
|
| 110 |
return PaginatedResponse(
|
| 111 |
items=items,
|