Skip to content

Fix 500 creating attendance_cleanup_rule (incomplete DataSource entity set) - #152

Merged
buzz-code merged 2 commits into
mainfrom
claude/fix-attendance-cleanup-rule-datasource
Aug 23, 2026
Merged

buzz-code merged 2 commits into
mainfrom
claude/fix-attendance-cleanup-rule-datasource

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

Summary

Fixes the production 500 on POST /attendance_cleanup_rule:

Entity metadata for Klass#klassType was not found. Check if you specified a correct
entity object and if it's connected in the connection options.

AttendanceCleanupRule.fillFields() builds an ad-hoc DataSource via getDataSource([Lesson, Klass, User]). Klass has @ManyToOne relations to KlassType and Teacher (and Lesson to LessonKlassName) that TypeORM must resolve when building entity metadata — even though this code never touches those relations. Any relation target missing from the entities array throws at DataSource.initialize().

Every other entity in this codebase that resolves through Lesson/Klass this way (AttReport, Grade, KnownAbsence, LessonSchedule, StudentKlass) already includes the full closure (KlassType, Teacher, sometimes LessonKlassName) — this one was left incomplete.

Fix: getDataSource([Lesson, Klass, KlassType, Teacher, User, LessonKlassName]).

Testing

  • Reproduced the exact production error against a real MySQL instance by calling getDataSource with the old entity set, and confirmed it succeeds with the fixed set.
  • Fresh submodule checkout: tsc --noEmit clean; yarn test — 111 suites / 994 tests passed.

Note: the existing fillFields unit test mocks getDataSource entirely, so it couldn't catch this class of bug (a real TypeORM metadata-build error) — that's why it slipped through CI.

🤖 Generated with Claude Code


Generated by Claude Code

fillFields() built an ad-hoc DataSource with getDataSource([Lesson,
Klass, User]), but Klass has relations to KlassType and Teacher (and
Lesson to LessonKlassName) that TypeORM must resolve when building
entity metadata, even though this code never touches them. Missing
targets throw at DataSource.initialize():

  Entity metadata for Klass#klassType was not found.

Reproduced against a real MySQL instance and confirmed fixed.

Every other entity in this codebase resolving Lesson/Klass this way
(AttReport, Grade, KnownAbsence, LessonSchedule, StudentKlass) already
includes the full closure - this one was left incomplete.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011dEYULADLgGNfZ4nv6gz8s
Copilot AI lite review requested due to automatic review settings August 23, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Add regression coverage for DataSource metadata initialization or the full entity set.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes a production 500 by supplying the complete TypeORM entity metadata closure.

Changes:

  • Adds missing relation-target imports.
  • Expands the temporary DataSource entity set.
File summaries
File Summary
server/src/db/entities/AttendanceCleanupRule.entity.ts Completes entity metadata configuration; regression coverage is still needed.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ntity closure

Addresses Copilot review comment on PR #152: the existing fillFields
tests mock getDataSource entirely, so they'd still pass if a relation
target were dropped from the entity list again - exactly what caused
the production 500.

This test doesn't mock getDataSource, so it builds real TypeORM
metadata (against Jest's default sqlite in-memory databaseConfig).
Confirmed it fails with the exact production error when reverted to
the old [Lesson, Klass, User] list, and passes with the fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011dEYULADLgGNfZ4nv6gz8s
@buzz-code
buzz-code merged commit 8bb2194 into main Aug 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants