Skip to content

Commit 46fc060

Browse files
hongalexacocuzzo
andauthored
fix(pubsub): allow clearing of topic schema (#7980)
Co-authored-by: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com>
1 parent 2296f00 commit 46fc060

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pubsub/pstest/fake.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ func (s *GServer) UpdateTopic(_ context.Context, req *pb.UpdateTopicRequest) (*p
362362
}
363363
t.proto.MessageRetentionDuration = req.Topic.MessageRetentionDuration
364364
case "schema_settings":
365-
// Clear this field.
366-
t.proto.SchemaSettings = &pb.SchemaSettings{}
365+
t.proto.SchemaSettings = req.Topic.SchemaSettings
367366
case "schema_settings.schema":
368367
if t.proto.SchemaSettings == nil {
369368
t.proto.SchemaSettings = &pb.SchemaSettings{}

pubsub/topic.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ func (t *Topic) updateRequest(cfg TopicConfigToUpdate) *pb.UpdateTopicRequest {
407407
}
408408
paths = append(paths, "message_retention_duration")
409409
}
410+
// Updating SchemaSettings' field masks are more complicated here
411+
// since each field should be able to be independently edited, while
412+
// preserving the current values for everything else. We also denote
413+
// the zero value SchemaSetting to mean clearing or removing schema
414+
// from the topic.
410415
if cfg.SchemaSettings != nil {
411416
pt.SchemaSettings = schemaSettingsToProto(cfg.SchemaSettings)
412417
clearSchema := true
@@ -426,9 +431,10 @@ func (t *Topic) updateRequest(cfg TopicConfigToUpdate) *pb.UpdateTopicRequest {
426431
paths = append(paths, "schema_settings.last_revision_id")
427432
clearSchema = false
428433
}
429-
// Clear the schema if none of it's value changes.
434+
// Clear the schema if all of its values are equal to the zero value.
430435
if clearSchema {
431436
paths = append(paths, "schema_settings")
437+
pt.SchemaSettings = nil
432438
}
433439
}
434440
return &pb.UpdateTopicRequest{

pubsub/topic_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ func TestUpdateTopic_SchemaSettings(t *testing.T) {
342342
if err != nil {
343343
t.Fatal(err)
344344
}
345-
if !testutil.Equal(config3.SchemaSettings, settings, opt) {
346-
t.Errorf("\ngot %+v\nwant %+v", config3.SchemaSettings, settings)
345+
if config3.SchemaSettings != nil {
346+
t.Errorf("got: %+v, want nil", config3.SchemaSettings)
347347
}
348348
}
349349

0 commit comments

Comments
 (0)