From 24a3610c4ca8f931486950f45d1c5964a2f129ac Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 8 May 2026 22:22:52 +0000 Subject: [PATCH] Correctly build updaters with New Otherwise we have nil columns --- db/query/publicreport/compliance.go | 9 ++++++++- db/query/publicreport/report.go | 7 +++++++ db/updater.go | 12 ++++++++++-- platform/publicreport.go | 2 +- platform/signal.go | 2 +- resource/publicreport_compliance.go | 4 ++-- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/db/query/publicreport/compliance.go b/db/query/publicreport/compliance.go index c5d2b555..df38265a 100644 --- a/db/query/publicreport/compliance.go +++ b/db/query/publicreport/compliance.go @@ -13,9 +13,16 @@ import ( type ComplianceUpdater = db.Updater[table.ComplianceTable, model.Compliance] +func NewComplianceUpdater() ComplianceUpdater { + return db.NewUpdater[table.ComplianceTable, model.Compliance]( + table.Compliance, + table.Compliance.ReportID, + ) +} + func NewUpdaterCompliance() db.Updater[table.ComplianceTable, model.Compliance] { return db.NewUpdater[table.ComplianceTable, model.Compliance]( - *table.Compliance, + table.Compliance, table.Compliance.ReportID, ) diff --git a/db/query/publicreport/report.go b/db/query/publicreport/report.go index 556bd92e..89e9d731 100644 --- a/db/query/publicreport/report.go +++ b/db/query/publicreport/report.go @@ -15,6 +15,13 @@ import ( type ReportUpdater = db.Updater[table.ReportTable, model.Report] +func NewReportUpdater() ReportUpdater { + return db.NewUpdater[table.ReportTable, model.Report]( + table.Report, + table.Report.ID, + ) +} + func ReportInsert(ctx context.Context, txn db.Ex, m model.Report) (model.Report, error) { statement := table.Report.INSERT(table.Report.MutableColumns). MODEL(m). diff --git a/db/updater.go b/db/updater.go index 1d6fdf9f..eb36bcb0 100644 --- a/db/updater.go +++ b/db/updater.go @@ -2,6 +2,7 @@ package db import ( "context" + "fmt" //"github.com/go-jet/jet/v2" "github.com/go-jet/jet/v2/postgres" @@ -17,6 +18,13 @@ type Updater[T postgres.Table, M any] struct { } func (u Updater[T, M]) Execute(ctx context.Context, txn Ex, pk_values ...interface{}) error { + // We get syntax errors from the database if there are no updates to perform + if u.Columns == nil { + return fmt.Errorf("nil columns") + } + if len(u.Columns) == 0 { + return nil + } statement := u.Table. UPDATE(u.Columns). MODEL(u.Model). @@ -47,12 +55,12 @@ func (u *Updater[T, M]) Unset(c postgres.Column) { } } func NewUpdater[T postgres.Table, M any]( - table T, + table *T, pk_columns ...postgres.ColumnInteger, ) Updater[T, M] { return Updater[T, M]{ Columns: postgres.ColumnList{}, - Table: table, + Table: *table, buildWhere: func(pk_values ...interface{}) postgres.BoolExpression { conditions := make([]postgres.BoolExpression, len(pk_columns)) for i, col := range pk_columns { diff --git a/platform/publicreport.go b/platform/publicreport.go index 05c1abf0..e7b686bc 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -89,7 +89,7 @@ func PublicReportInvalid(ctx context.Context, user User, public_id string) error } now := time.Now() - report_updater := querypublicreport.ReportUpdater{} + report_updater := querypublicreport.NewReportUpdater() report_updater.Model.Reviewed = &now report_updater.Set(tablepublicreport.Report.Reviewed) reporter_id := int32(user.ID) diff --git a/platform/signal.go b/platform/signal.go index 470ac770..1bff3a7d 100644 --- a/platform/signal.go +++ b/platform/signal.go @@ -152,7 +152,7 @@ func SignalCreateFromPublicreport(ctx context.Context, user User, report_id stri if err != nil { return nil, fmt.Errorf("create signal: %w", err) } - report_updater := querypublicreport.ReportUpdater{} + report_updater := querypublicreport.NewReportUpdater() now := time.Now() report_updater.Model.Reviewed = &now report_updater.Set(tablepublicreport.Report.Reviewed) diff --git a/resource/publicreport_compliance.go b/resource/publicreport_compliance.go index c6ad7fca..a5b01659 100644 --- a/resource/publicreport_compliance.go +++ b/resource/publicreport_compliance.go @@ -152,9 +152,9 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicR if public_id == "" { return nil, nhttp.NewBadRequest("You must provide an ID") } - report_updater := querypublicreport.ReportUpdater{} + report_updater := querypublicreport.NewReportUpdater() //report_setter := models.PublicreportReportSetter{} - compliance_updater := querypublicreport.ComplianceUpdater{} + compliance_updater := querypublicreport.NewComplianceUpdater() //compliance_setter := models.PublicreportComplianceSetter{} var location *types.Location if prf.Location.IsValue() {