Preserve external_id in customer deletion webhooks#9665
Open
pieterbeulque wants to merge 3 commits intomainfrom
Open
Preserve external_id in customer deletion webhooks#9665pieterbeulque wants to merge 3 commits intomainfrom
pieterbeulque wants to merge 3 commits intomainfrom
Conversation
When a customer is deleted, soft_delete() clears external_id from the DB column (to allow ID recycling) before the async webhook/event jobs run. As a result, the customer.deleted webhook payload always had external_id: null. The original value is already preserved in user_metadata["__external_id"] for debugging. This fix reads it back in both the customer_webhook and customer_event tasks when processing customer_deleted events, so the outgoing payload correctly reflects the external_id the customer had at the time of deletion. https://claude.ai/code/session_014o3Ar2JdpnY1DSr3TjLh3P
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Verifies that the external_id is correctly restored from user_metadata in the customer_webhook task when processing customer.deleted events, covering both the case where external_id was set and where it was not. https://claude.ai/code/session_014o3Ar2JdpnY1DSr3TjLh3P
This comment has been minimized.
This comment has been minimized.
MagicMock isn't a descriptor so self isn't bound; the recorded args are (session, redis, event_type, customer), making customer at index 3. https://claude.ai/code/session_014o3Ar2JdpnY1DSr3TjLh3P
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Summary
I lost the ticket, but this was reported somewhere in Plain. It makes sense that you want to have access to the
external_idfrom a deleted customer to sync back to your system.🎯 What
customer_webhook()to restoreexternal_idfromuser_metadata["__external_id"]when processingcustomer_deletedeventscustomer_event()to fall back to the preserved__external_idvalue when the databaseexternal_idisNone🤔 Why
When a customer is deleted, the
external_idis cleared in the database to allow the ID to be recycled for new customers. However, webhook consumers need the originalexternal_idto properly identify which customer was deleted. The__external_idis preserved inuser_metadatafor this purpose, but wasn't being used in the webhook payload.🔧 How
customer_webhook(): Added logic to check if we're processing acustomer_deletedevent with aNoneexternal_id, and if so, restore it fromuser_metadatacustomer_event(): Added a fallback to use the preserved__external_idwhen the currentexternal_idisNoneBoth changes include explanatory comments documenting the ID recycling behavior.
🧪 Testing
uv run task testfor backend,pnpm testfor frontend)uv run task lint && uv run task lint_typesfor backend)Test Instructions
customer_deletedwebhook event includes the originalexternal_idin the payloadexternal_idhttps://claude.ai/code/session_014o3Ar2JdpnY1DSr3TjLh3P