diff --git a/mmv1/products/firestore/Field.yaml b/mmv1/products/firestore/Field.yaml index 92a71cc0b203..bd67a668a598 100644 --- a/mmv1/products/firestore/Field.yaml +++ b/mmv1/products/firestore/Field.yaml @@ -20,6 +20,8 @@ immutable: false update_verb: :PATCH update_mask: true create_verb: :PATCH +error_retry_predicates: + ["transport_tpg.FirestoreField409RetryUnderlyingDataChanged"] description: | Represents a single field in the database. Fields are grouped by their "Collection Group", which represent all collections diff --git a/mmv1/third_party/terraform/transport/error_retry_predicates.go b/mmv1/third_party/terraform/transport/error_retry_predicates.go index c1674aa80fd7..d7c21e6fef94 100644 --- a/mmv1/third_party/terraform/transport/error_retry_predicates.go +++ b/mmv1/third_party/terraform/transport/error_retry_predicates.go @@ -320,6 +320,16 @@ func DatastoreIndex409Contention(err error) (bool, string) { return false, "" } +// relevant for firestore in datastore mode +func FirestoreField409RetryUnderlyingDataChanged(err error) (bool, string) { + if gerr, ok := err.(*googleapi.Error); ok { + if gerr.Code == 409 && strings.Contains(gerr.Body, "Please retry, underlying data changed") { + return true, "underlying data changed - retrying" + } + } + return false, "" +} + func IapClient409Operation(err error) (bool, string) { if gerr, ok := err.(*googleapi.Error); ok { if gerr.Code == 409 && strings.Contains(strings.ToLower(gerr.Body), "operation was aborted") { diff --git a/mmv1/third_party/terraform/transport/error_retry_predicates_test.go b/mmv1/third_party/terraform/transport/error_retry_predicates_test.go index 8288bfc1e19d..a5f9b61e044a 100644 --- a/mmv1/third_party/terraform/transport/error_retry_predicates_test.go +++ b/mmv1/third_party/terraform/transport/error_retry_predicates_test.go @@ -170,3 +170,14 @@ func TestIsSwgAutogenRouterRetryableError_notReady(t *testing.T) { t.Errorf("Error not detected as retryable") } } + +func TestFirestoreField409_retryUnderlyingDataChanged(t *testing.T) { + err := googleapi.Error{ + Code: 409, + Body: "Please retry, underlying data changed", + } + isRetryable, _ := FirestoreField409RetryUnderlyingDataChanged(&err) + if !isRetryable { + t.Errorf("Error not detected as retryable") + } +}