Repository navigation
Conversation
POST /att_report/bulk returned HTTP 500 (MySQL 1366) when bulk payloads
contained non-integer strings for klassReferenceId ('כל') or
studentReferenceId ('not-a-number'). These columns had only
@ValidateIf/@isnotempty and no numeric validation, unlike year/klassId/
lessonId which got @NumberType + @isnumber({maxDecimalPlaces:0}) in #186.
Adds the same validators to studentReferenceId, klassReferenceId,
teacherReferenceId and lessonReferenceId (all int columns), so invalid
values now fail validation with 400 instead of reaching MySQL.
There was a problem hiding this comment.
🟡 Changes recommended
@ValidateIf can skip validation when a timezone field is present, allowing invalid IDs to reach MySQL.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes AttReport bulk inserts that return HTTP 500 for non-numeric reference IDs.
Changes:
- Adds numeric validation to four integer reference ID fields.
- Preserves existing numeric-string coercion behavior.
File summaries
| File | Summary |
|---|---|
server/src/db/entities/AttReport.entity.ts |
Adds reference-ID validation decorators; validation can still be bypassed when timezone fields are present. |
Review details
Suppressed comments (3)
server/src/db/entities/AttReport.entity.ts:135
@ValidateIfdisables these validators whenteacherIdis present.fillFields()returns any truthyteacherReferenceIdunchanged, so a payload containing both fields with a non-numeric reference ID still reaches the integer column and can produce HTTP 500. Make this validation depend only on whetherteacherReferenceIdis supplied, or reject conflicting inputs.
@NumberType
@IsNumber({ maxDecimalPlaces: 0 }, { always: true })
server/src/db/entities/AttReport.entity.ts:153
@ValidateIfdisables these validators whenklassIdis present.fillFields()returns any truthyklassReferenceIdunchanged, so a payload containing both fields with a non-numeric reference ID still reaches the integer column and can produce HTTP 500. Make this validation depend only on whetherklassReferenceIdis supplied, or reject conflicting inputs.
@NumberType
@IsNumber({ maxDecimalPlaces: 0 }, { always: true })
server/src/db/entities/AttReport.entity.ts:169
@ValidateIfdisables these validators whenlessonIdis present.fillFields()returns any truthylessonReferenceIdunchanged, so a payload containing both fields with a non-numeric reference ID still reaches the integer column and can produce HTTP 500. Make this validation depend only on whetherlessonReferenceIdis supplied, or reject conflicting inputs.
@NumberType
@IsNumber({ maxDecimalPlaces: 0 }, { always: true })
- 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.
| @NumberType | ||
| @IsNumber({ maxDecimalPlaces: 0 }, { always: true }) |
…ling bypass QA found a bypass in 5ce3752: the @ValidateIf predicates gated ALL validation on the tz/id sibling being empty, so a payload supplying BOTH studentTz AND studentReferenceId='garbage' skipped @isnumber and hit MySQL 1366 -> HTTP 500 again. Predicates now run validation whenever the referenceId value is present (!== undefined && !== null), regardless of the sibling field. Adds regression spec proving 'garbage' is rejected even when the sibling tz/id is also supplied, plus tz/id-only payloads still pass.
|
QA-bypass fix pushed in db58962. Bypass: the Fix: all 4 ReferenceId predicates ( Regression spec:
|
…ling bypass QA found the same bypass PR #188 (db58962) fixed for AttReport in the sibling-gated @ValidateIf predicates: a payload supplying BOTH the tz/id sibling AND referenceId='garbage' made the predicate false, skipping @isnumber and reaching the MySQL INT column (1366 -> 500). Predicates on every *ReferenceId field now run validation whenever the value is present (field !== undefined && field !== null), regardless of the sibling tz/id field — matching db58962's exact form. The sibling-guarding @ValidateIf blocks (e.g. !Boolean(studentReferenceId) above studentTz) are untouched; @IsNotEmpty/@IsOptional kept as-is. Fields without a @ValidateIf (reportGroupSessionId x2, Student.year, Lesson/Klass/KlassType teacherReferenceId, KnownAbsence.lessonReferenceId, AttendanceCleanupRule ReferenceIds) needed no predicate change. AttReport's four ReferenceId fields also gain the @NumberType + @isnumber pair on this branch (5ce3752 added it on the unmerged PR #188; without it the predicates had no numeric validator to run, and the required both-present regression test cannot pass). Regression tests added: 'garbage' studentReferenceId rejected even when studentTz is also supplied, for Grade and AttReport (89 -> 91 tests).
|
נסגר ככפילות: התיקון כאן כלול ב-#190 (מכסה את AttReport ועוד 9 ישויות, כולל הבדיקות). |
…olumns) Extends the PR buzz-code#186 / PR buzz-code#188 @NumberType + @isnumber({maxDecimalPlaces:0}) fix to the numeric ReferenceId/int columns still missing it, so a non-numeric string fails class-validator with a clear 400 instead of reaching the MySQL INT column as an HTTP-500: - AttReport.reportGroupSessionId, Grade.reportGroupSessionId - Grade: studentReferenceId, teacherReferenceId, lessonReferenceId - AttendanceCleanupRule: lessonReferenceId, klassReferenceId - StudentKlass: studentReferenceId, klassReferenceId - KnownAbsence: studentReferenceId, lessonReferenceId - Lesson/LessonSchedule/Klass/KlassType: teacherReferenceId - Student.year Bare fields get the full PR buzz-code#186 pattern (@IsOptional({always:true}) + pair); fields with existing @ValidateIf/@IsNotEmpty/@IsOptional keep them and only gain the @NumberType + @isnumber pair right before @column, matching the placement PR buzz-code#188 used on AttReport. The ValidateIf predicates all include '&& Boolean(field)', so omitted values skip validation and partial updates keep passing. New spec mirrors the CRUD validation pipeline (plainToInstance + validate with CREATE/UPDATE groups): garbage rejected on create and update, integers and numeric strings (NumberType coercion) accepted, partial updates omitting the fields still pass, plus full-payload create scenarios for Grade and Student.
Bug
POST /att_report/bulkreturned HTTP 500 when the payload contained non-integer values for the AttReport integer reference columns:Incorrect integer value: 'כל' for column 'klassReferenceId'Incorrect integer value: 'not-a-number' for column 'studentReferenceId'MySQL error 1366 (ER_TRUNCATED_WRONG_VALUE_FOR_FIELD).
Root cause
In
server/src/db/entities/AttReport.entity.ts,studentReferenceIdandklassReferenceIdhad only@ValidateIf/@IsNotEmpty— no numeric validation — so non-numeric strings passed validation, survivedfillFields()(findOneAndAssignReferenceIdpasses the value through when set), and hit theintDB column.The analogous fields
year,klassId,lessonIdalready had@NumberType+@IsNumber({ maxDecimalPlaces: 0 }, { always: true })from #186; the ReferenceId columns were missed.Fix
Adds the same validators to all four int ReferenceId columns:
studentReferenceIdklassReferenceIdteacherReferenceId(same latent gap, fixed for consistency)lessonReferenceId(same latent gap, fixed for consistency)@NumberTypepasses non-numeric strings through unchanged, so@IsNumbernow rejects them with a 400 instead of a MySQL 500. Numeric strings (e.g."123") are still coerced to numbers, matching the existing fields' behavior.Verification
validateBulk(the real bulk path:plainToInstance+validate) rejects{ studentReferenceId: 'כל' }and{ klassReferenceId: 'not-a-number' }, and still accepts numeric reference IDs and tz-based payloads.yarn test: 115/117 suites pass; the 2 failing suites (attendance-cleanup-sweep.handler,year.util.behavior) fail identically on cleanmain— pre-existing, unrelated.No refactor — validators only.