[cloud functions] Handle race condition when deleting active configurations

When the last two active configurations are deleted, one call can check
for empty and delete, before the other call checks for empty.

Change-Id: Ib03dc12635630b558419ed4747fcde70d6969602
Reviewed-on: https://dart-review.googlesource.com/c/dart_ci/+/139340
Reviewed-by: Alexander Thomas <athom@google.com>
diff --git a/functions/node/firestore_impl.dart b/functions/node/firestore_impl.dart
index 5e4b6e1..18c4b33 100644
--- a/functions/node/firestore_impl.dart
+++ b/functions/node/firestore_impl.dart
@@ -252,7 +252,8 @@
             Firestore.fieldValues.arrayRemove([configuration]));
       await document.updateData(removeConfiguration);
       activeResult = (await document.get()).data.toMap();
-      if (activeResult['active_configurations'].isNotEmpty) return;
+      if (!activeResult.containsKey('active_configurations') ||
+          activeResult['active_configurations'].isNotEmpty) return;
     }
     final deleteActiveFields = UpdateData()
       ..setFieldValue('active_configurations', Firestore.fieldValues.delete())