Skip to content

Commit

Permalink
fix(pubsub): fix issue preventing clearing BQ subscription (#8040)
Browse files Browse the repository at this point in the history
* fix(pubsub): allow clearing of bq subscriptions

* update behavior in fake as well
  • Loading branch information
hongalex committed Jun 5, 2023
1 parent 31040e8 commit 0366bf3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pubsub/pstest/fake.go
Expand Up @@ -605,9 +605,15 @@ func (s *GServer) UpdateSubscription(_ context.Context, req *pb.UpdateSubscripti
sub.proto.PushConfig = req.Subscription.PushConfig

case "bigquery_config":
// If bq config is nil here, it will have been cleared.
// Otherwise, we'll consider the subscription active if any table is set.
sub.proto.BigqueryConfig = req.GetSubscription().GetBigqueryConfig()
if sub.proto.GetBigqueryConfig().GetTable() != "" {
sub.proto.GetBigqueryConfig().State = pb.BigQueryConfig_ACTIVE
if sub.proto.GetBigqueryConfig() != nil {
if sub.proto.GetBigqueryConfig().GetTable() != "" {
sub.proto.BigqueryConfig.State = pb.BigQueryConfig_ACTIVE
} else {
return nil, status.Errorf(codes.InvalidArgument, "table must be provided")
}
}

case "ack_deadline_seconds":
Expand Down
5 changes: 5 additions & 0 deletions pubsub/subscription.go
Expand Up @@ -265,6 +265,11 @@ func (bc *BigQueryConfig) toProto() *pb.BigQueryConfig {
if bc == nil {
return nil
}
// If the config is zero valued, this is the sentinel for
// clearing bigquery config and switch back to pull.
if *bc == (BigQueryConfig{}) {
return nil
}
pbCfg := &pb.BigQueryConfig{
Table: bc.Table,
UseTopicSchema: bc.UseTopicSchema,
Expand Down

0 comments on commit 0366bf3

Please sign in to comment.