Spaces:
Runtime error
Runtime error
Change trade_date to String type to avoid SQLAlchemy datetime conversion errors
Browse files- apps/api/routers/trade_hf.py +8 -3
- packages/core/models.py +1 -1
apps/api/routers/trade_hf.py
CHANGED
|
@@ -81,10 +81,15 @@ async def search_trade_records(
|
|
| 81 |
# 转换为响应格式
|
| 82 |
items = []
|
| 83 |
for r in records:
|
| 84 |
-
# 处理
|
| 85 |
-
|
| 86 |
-
if not
|
| 87 |
trade_date = datetime(2020, 1, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
items.append(TradeRecordResponse(
|
| 90 |
record_id=r.record_id,
|
|
|
|
| 81 |
# 转换为响应格式
|
| 82 |
items = []
|
| 83 |
for r in records:
|
| 84 |
+
# 处理日期字符串:SQLAlchemy现在返回字符串
|
| 85 |
+
trade_date_str = r.trade_date
|
| 86 |
+
if not trade_date_str or trade_date_str.strip() == '':
|
| 87 |
trade_date = datetime(2020, 1, 1)
|
| 88 |
+
else:
|
| 89 |
+
try:
|
| 90 |
+
trade_date = datetime.fromisoformat(trade_date_str.replace(' ', 'T'))
|
| 91 |
+
except:
|
| 92 |
+
trade_date = datetime(2020, 1, 1)
|
| 93 |
|
| 94 |
items.append(TradeRecordResponse(
|
| 95 |
record_id=r.record_id,
|
packages/core/models.py
CHANGED
|
@@ -33,7 +33,7 @@ class StandardTradeRecord(Base):
|
|
| 33 |
|
| 34 |
source_country = Column(String(10), index=True, nullable=False, comment="数据来源国")
|
| 35 |
trade_direction = Column(String(10), index=True, nullable=False, comment="贸易方向: import / export")
|
| 36 |
-
trade_date = Column(
|
| 37 |
|
| 38 |
importer_name = Column(String(255), index=True, nullable=True, comment="进口商名称(清洗后)")
|
| 39 |
exporter_name = Column(String(255), index=True, nullable=True, comment="出口商名称(清洗后)")
|
|
|
|
| 33 |
|
| 34 |
source_country = Column(String(10), index=True, nullable=False, comment="数据来源国")
|
| 35 |
trade_direction = Column(String(10), index=True, nullable=False, comment="贸易方向: import / export")
|
| 36 |
+
trade_date = Column(String(50), index=True, nullable=True, comment="交易发生日期")
|
| 37 |
|
| 38 |
importer_name = Column(String(255), index=True, nullable=True, comment="进口商名称(清洗后)")
|
| 39 |
exporter_name = Column(String(255), index=True, nullable=True, comment="出口商名称(清洗后)")
|