Skip to content

Commit

Permalink
fix(pubsub): allow clearing of topic schema (#7980)
Browse files Browse the repository at this point in the history
Co-authored-by: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com>
  • Loading branch information
hongalex and acocuzzo committed May 24, 2023
1 parent 2296f00 commit 46fc060
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions pubsub/pstest/fake.go
Expand Up @@ -362,8 +362,7 @@ func (s *GServer) UpdateTopic(_ context.Context, req *pb.UpdateTopicRequest) (*p
}
t.proto.MessageRetentionDuration = req.Topic.MessageRetentionDuration
case "schema_settings":
// Clear this field.
t.proto.SchemaSettings = &pb.SchemaSettings{}
t.proto.SchemaSettings = req.Topic.SchemaSettings
case "schema_settings.schema":
if t.proto.SchemaSettings == nil {
t.proto.SchemaSettings = &pb.SchemaSettings{}
Expand Down
8 changes: 7 additions & 1 deletion pubsub/topic.go
Expand Up @@ -407,6 +407,11 @@ func (t *Topic) updateRequest(cfg TopicConfigToUpdate) *pb.UpdateTopicRequest {
}
paths = append(paths, "message_retention_duration")
}
// Updating SchemaSettings' field masks are more complicated here
// since each field should be able to be independently edited, while
// preserving the current values for everything else. We also denote
// the zero value SchemaSetting to mean clearing or removing schema
// from the topic.
if cfg.SchemaSettings != nil {
pt.SchemaSettings = schemaSettingsToProto(cfg.SchemaSettings)
clearSchema := true
Expand All @@ -426,9 +431,10 @@ func (t *Topic) updateRequest(cfg TopicConfigToUpdate) *pb.UpdateTopicRequest {
paths = append(paths, "schema_settings.last_revision_id")
clearSchema = false
}
// Clear the schema if none of it's value changes.
// Clear the schema if all of its values are equal to the zero value.
if clearSchema {
paths = append(paths, "schema_settings")
pt.SchemaSettings = nil
}
}
return &pb.UpdateTopicRequest{
Expand Down
4 changes: 2 additions & 2 deletions pubsub/topic_test.go
Expand Up @@ -342,8 +342,8 @@ func TestUpdateTopic_SchemaSettings(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !testutil.Equal(config3.SchemaSettings, settings, opt) {
t.Errorf("\ngot %+v\nwant %+v", config3.SchemaSettings, settings)
if config3.SchemaSettings != nil {
t.Errorf("got: %+v, want nil", config3.SchemaSettings)
}
}

Expand Down

0 comments on commit 46fc060

Please sign in to comment.