ICU-17341 Update UpdateControllerStatus to handle empty string descriptions. When reading from the server_controller database, NULL descriptions are cast to empty strings. To prevent violating the wt_description_too_short constraint in the wt_description domain, ensure that empty string descriptions are converted to nil before being passed. (#5894)

This commit is contained in:
Ryan Derr authored and GitHub committed 2025-07-02 13:45:26 -05:00
1 parent 4b51684517
commit 67d55f3743
2 files changed
+34 -6

No files matched your search

+12 -6
View File
@@ -95,12 +95,18 @@ func (r *Repository) UpdateControllerStatus(ctx context.Context, controller *Con
db.ExpBackoff{},
func(reader db.Reader, w db.Writer) error {
var err error
rowsUpdated, err = w.Exec(ctx, updateController,
[]any{
sql.Named("controller_address", controller.Address),
sql.Named("controller_description", controller.Description),
sql.Named("controller_private_id", controller.PrivateId),
})
params := []any{
sql.Named("controller_private_id", controller.PrivateId),
sql.Named("controller_address", controller.Address),
}
if controller.Description != "" {
params = append(params, sql.Named("controller_description", controller.Description))
} else {
params = append(params, sql.Named("controller_description", nil))
}
rowsUpdated, err = w.Exec(ctx, updateController, params)
switch {
case err != nil:
return errors.Wrap(ctx, err, op+":Update")
@@ -184,6 +184,28 @@ func TestRepository_UpdateControllerStatus(t *testing.T) {
require.Equal(t, 1, c)
},
},
"valid-ipv4-controller-remove-description": {
originalController: NewController("test", WithAddress("127.0.0.1"), WithDescription("short name description")),
updatedController: NewController("test", WithAddress("127.0.0.2")),
wantCount: 1,
cleanUpFunc: func(t *testing.T, rw *db.Db, privateId string) {
t.Helper()
c, err := rw.Exec(ctx, removeControllerSql, []any{privateId})
require.NoError(t, err)
require.Equal(t, 1, c)
},
},
"valid-ipv4-controller-no-description": {
originalController: NewController("test", WithAddress("127.0.0.1")),
updatedController: NewController("test", WithAddress("127.0.0.2")),
wantCount: 1,
cleanUpFunc: func(t *testing.T, rw *db.Db, privateId string) {
t.Helper()
c, err := rw.Exec(ctx, removeControllerSql, []any{privateId})
require.NoError(t, err)
require.Equal(t, 1, c)
},
},
}
for name, tt := range tests {