firebase / extensions

Source code for official Firebase extensions
https://firebase.google.com/products/extensions
Apache License 2.0
882 stars 373 forks source link

🐛 Critical: [delete-user-data] Recursive Deletion Fails to Remove Subcollections When Using Auto Discovery #2031

Closed cgilbu closed 2 months ago

cgilbu commented 2 months ago

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs for a specific extension in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

[REQUIRED] Step 2: Describe your configuration

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I have set the delete mode to "recursive" with the expectation that deleting a user would remove the user's document at the specified path, along with all its subcollections. However, while the document fields are deleted, its subcollections are not removed and remain intact in the database.

To reproduce this issue:

  1. Configure the extension with recursive delete mode and a Firestore path.
  2. Delete a user whose data is stored at the specified path.
  3. Check Firestore and observe that the main document is cleared but subcollections still exist.

This issue occurs not only with documents located using auto discovery but also with those specified directly in the Firestore paths. In both cases, the subcollections remain undeleted, despite the document fields being cleared.

I have checked the API logs and found no errors related to this issue. The deletion process appears to complete without error logs, but the expected behavior of recursive deletion is not achieved.

Expected result

When the extension is triggered, the specified user's document and all its subcollections should be completely deleted from Firestore.

Actual result

The document fields are deleted, but subcollections under the document are not deleted, remaining visible and intact in Firestore.

cgilbu commented 2 months ago

UPDATE: This issue is linked to "auto discovery"

Today, I conducted several additional tests. Initially, I uninstalled the extension and then reinstalled it with the same configurations as before, but this time with "auto discovery" disabled. Consequently, documents (and their subcollections) within "accounts/{UID}" were successfully deleted.

I then reconfigured the extension to enable "auto discovery" and ensured that "auto discovery search fields" were correctly set. Additionally, I adjusted "auto discovery search depth" to "3" just to be safe. As a result, the documents (and their subcollections) within "accounts/{UID}" were successfully deleted as before. However, documents located through "auto discovery", containing the specified "auto discovery search fields", were not entirely deleted; only the document fields were deleted, not the subcollections.

Just for reference: The documents discovered using "auto discovery" were located under "users/{customId}".

In summary:

9jorgeLuis commented 2 months ago

Similar issue here, in my case it doesn't delete the document found by the search field, I have automatic discovery configured, and the depth set to 3, but in my case the behavior seems to be random, sometimes all my documents are deleted but in other cases some of them or all remain, I've checked the logs and there doesn't seem to be any error.

cabljac commented 2 months ago

Thanks! Looking into this now

cabljac commented 2 months ago

I think i have the fix, just need to write some more tests, should be released this week.