fix: add values_callable to all SQLAlchemy Enum columns

SQLAlchemy 2.0 defaults to mapping Python enum *names* (OPEN, CLOSED)
to DB values, but MySQL stores lowercase *values* (open, closed).
This mismatch causes LookupError on read.

Adding values_callable=lambda x: [e.value for e in x] tells SQLAlchemy
to use the enum values for DB mapping.

Affected models: milestone, task, meeting, propose, support
This commit is contained in:
zhi
2026-03-19 09:38:37 +00:00
parent e938507a24
commit 43742f69da
5 changed files with 8 additions and 8 deletions

View File

@@ -17,7 +17,7 @@ class Propose(Base):
propose_code = Column(String(64), nullable=True, unique=True, index=True)
title = Column(String(255), nullable=False)
description = Column(Text, nullable=True)
status = Column(Enum(ProposeStatus), default=ProposeStatus.OPEN)
status = Column(Enum(ProposeStatus, values_callable=lambda x: [e.value for e in x]), default=ProposeStatus.OPEN)
project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)
created_by_id = Column(Integer, ForeignKey("users.id"), nullable=True)