Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pubsub): allow clearing of topic schema #7980

Merged
merged 3 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions pubsub/pstest/fake.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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