3v324v23 commited on
Commit
d4f9f67
·
1 Parent(s): 66d6c79

Change trade_date to String type to avoid SQLAlchemy datetime conversion errors

Browse files
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
- # 处理日期:构造典而不是使用from_attributes
85
- trade_date = r.trade_date
86
- if not trade_date or (isinstance(trade_date, str) and trade_date.strip() == ''):
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(DateTime, index=True, nullable=False, comment="交易发生日期")
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="出口商名称(清洗后)")