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

@@ -22,8 +22,8 @@ class Meeting(Base):
id = Column(Integer, primary_key=True, index=True) id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False) title = Column(String(255), nullable=False)
description = Column(Text, nullable=True) description = Column(Text, nullable=True)
status = Column(Enum(MeetingStatus), default=MeetingStatus.SCHEDULED) status = Column(Enum(MeetingStatus, values_callable=lambda x: [e.value for e in x]), default=MeetingStatus.SCHEDULED)
priority = Column(Enum(MeetingPriority), default=MeetingPriority.MEDIUM) priority = Column(Enum(MeetingPriority, values_callable=lambda x: [e.value for e in x]), default=MeetingPriority.MEDIUM)
meeting_code = Column(String(64), nullable=True, unique=True, index=True) meeting_code = Column(String(64), nullable=True, unique=True, index=True)
project_id = Column(Integer, ForeignKey("projects.id"), nullable=False) project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)

View File

@@ -17,7 +17,7 @@ class Milestone(Base):
id = Column(Integer, primary_key=True, index=True) id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False) title = Column(String(255), nullable=False)
description = Column(Text, nullable=True) description = Column(Text, nullable=True)
status = Column(Enum(MilestoneStatus), default=MilestoneStatus.OPEN) status = Column(Enum(MilestoneStatus, values_callable=lambda x: [e.value for e in x]), default=MilestoneStatus.OPEN)
milestone_code = Column(String(64), nullable=True, unique=True, index=True) milestone_code = Column(String(64), nullable=True, unique=True, index=True)
due_date = Column(DateTime(timezone=True), nullable=True) due_date = Column(DateTime(timezone=True), nullable=True)
planned_release_date = Column(DateTime(timezone=True), nullable=True) planned_release_date = Column(DateTime(timezone=True), nullable=True)

View File

@@ -17,7 +17,7 @@ class Propose(Base):
propose_code = Column(String(64), nullable=True, unique=True, index=True) propose_code = Column(String(64), nullable=True, unique=True, index=True)
title = Column(String(255), nullable=False) title = Column(String(255), nullable=False)
description = Column(Text, nullable=True) 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) project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)
created_by_id = Column(Integer, ForeignKey("users.id"), nullable=True) created_by_id = Column(Integer, ForeignKey("users.id"), nullable=True)

View File

@@ -22,8 +22,8 @@ class Support(Base):
id = Column(Integer, primary_key=True, index=True) id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False) title = Column(String(255), nullable=False)
description = Column(Text, nullable=True) description = Column(Text, nullable=True)
status = Column(Enum(SupportStatus), default=SupportStatus.OPEN) status = Column(Enum(SupportStatus, values_callable=lambda x: [e.value for e in x]), default=SupportStatus.OPEN)
priority = Column(Enum(SupportPriority), default=SupportPriority.MEDIUM) priority = Column(Enum(SupportPriority, values_callable=lambda x: [e.value for e in x]), default=SupportPriority.MEDIUM)
support_code = Column(String(64), nullable=True, unique=True, index=True) support_code = Column(String(64), nullable=True, unique=True, index=True)
project_id = Column(Integer, ForeignKey("projects.id"), nullable=False) project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)

View File

@@ -23,8 +23,8 @@ class Task(Base):
id = Column(Integer, primary_key=True, index=True) id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False) title = Column(String(255), nullable=False)
description = Column(Text, nullable=True) description = Column(Text, nullable=True)
status = Column(Enum(TaskStatus), default=TaskStatus.OPEN) status = Column(Enum(TaskStatus, values_callable=lambda x: [e.value for e in x]), default=TaskStatus.OPEN)
priority = Column(Enum(TaskPriority), default=TaskPriority.MEDIUM) priority = Column(Enum(TaskPriority, values_callable=lambda x: [e.value for e in x]), default=TaskPriority.MEDIUM)
task_code = Column(String(64), nullable=True, unique=True, index=True) task_code = Column(String(64), nullable=True, unique=True, index=True)
# Task type/subtype (replaces old issue_type/issue_subtype) # Task type/subtype (replaces old issue_type/issue_subtype)