Repository navigation
Fix 500 creating attendance_cleanup_rule (incomplete DataSource entity set) - #152
Merged
Merged
Conversation
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
There was a problem hiding this comment.
🟡 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
DataSourceentity 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the production 500 on
POST /attendance_cleanup_rule:AttendanceCleanupRule.fillFields()builds an ad-hocDataSourceviagetDataSource([Lesson, Klass, User]).Klasshas@ManyToOnerelations toKlassTypeandTeacher(andLessontoLessonKlassName) 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 atDataSource.initialize().Every other entity in this codebase that resolves through
Lesson/Klassthis way (AttReport,Grade,KnownAbsence,LessonSchedule,StudentKlass) already includes the full closure (KlassType,Teacher, sometimesLessonKlassName) — this one was left incomplete.Fix:
getDataSource([Lesson, Klass, KlassType, Teacher, User, LessonKlassName]).Testing
getDataSourcewith the old entity set, and confirmed it succeeds with the fixed set.tsc --noEmitclean;yarn test— 111 suites / 994 tests passed.Note: the existing
fillFieldsunit test mocksgetDataSourceentirely, 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