Fix #16: Repository layer code review: fix critical transaction bug and high-severity issues #17
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/issue-16"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Automated fix via Hermes Agent. Closes #16
Fixes
Critical
CreateBatchshadowederrwith:=in loop, causing partial commits on row-insert failure and silently droppingtx.Commit()errors. Fixed with named return andexecErrloop variable.High
OrderBywas concatenated raw into SQL query (injection surface). Added whitelist validation at repo level (independent of HTTP allowlist).Organization().ListdroppedargsinSelectContextcall — IN placeholders were unbound, always erroring with IDs filter.CourseRepository.Getwrappedsql.ErrNoRowswithout translating toErrNotFound, breaking the port contract.Medium
Createnow returns the created entity viaGetinstead of emptyCourse{}.Organization.Create.time.Now()totime.Now().UTC()for consistency across repos.C1: CreateBatch shadowed err with := in loop, causing partial commits on failure. Fixed with named return and execErr loop variable. H1: OrderBy concatenated raw into SQL query. Added whitelist validation. H2: Organization.List dropped query args in SelectContext call. H3: CourseRepository.Get wrapped sql.ErrNoRows without translating to ErrNotFound, breaking the port contract. Medium: Create now returns the created entity via Get; fixed prepared statement leak in Organization.Create; unified time.Now() to UTC.ca32d865b2to7bf95f136f@ -77,2 +78,4 @@direction = "DESC"}allowedOrderBy := map[string]bool{Use
map[string]struct{}for fields white-list.Review Responses
[sqlite_course_repository.go:81] - @frx:
Done. Changed
map[string]bool→map[string]struct{}for theallowedOrderBywhitelist (set semantics, zero-value footprint). Updated the lookup to the comma-ok idiom (if _, ok := allowedOrderBy[key]; !ok) sincestruct{}can't be used as a boolean directly.Commit
590fed2pushed to this branch.Review Responses
[internal/kurious/adapters/sqlite_course_repository.go] - @frx:
Done. Changed
map[string]boolto the idiomaticmap[string]struct{}{}with the comma-ok lookup pattern (if _, ok := allowedOrderBy[params.OrderBy]; !ok). Committed in590fed2, pushed tofix/issue-16.All feedback from both reviews has been addressed. Ready for re-review.
Review Responses
[internal/kurious/adapters/sqlite_course_repository.go] - @frx:
Done. Changed
allowedOrderByfrommap[string]booltomap[string]struct{}— zero-size value type is idiomatic Go for set-style membership checks. Lookup updated to comma-ok form:if _, ok := allowedOrderBy[params.OrderBy]; !ok.Commit:
590fed2Review Responses
[internal/kurious/adapters/sqlite_course_repository.go] - @frx:
Done. Changed
map[string]booltomap[string]struct{}for theallowedOrderBywhitelist — set semantics, zero-value entries instead oftruebooleans. Updated the lookup to the comma-ok idiom (if _, ok := allowedOrderBy[...]; !ok). See commit590fed2.590fed2go build ./...passesgo test ./...all pass