Flip WhatsApp URNs to the new scheme model (management command, BSUID contacts only)#6710
Closed
norkans7 wants to merge 1 commit into
Closed
Flip WhatsApp URNs to the new scheme model (management command, BSUID contacts only)#6710norkans7 wants to merge 1 commit into
norkans7 wants to merge 1 commit into
Conversation
|
Claude finished @norkans7's task in 4m 20s —— View job PR Review
SummaryOverall this looks solid — the two-pass flip, A few things worth surfacing (all inline):
Nothing here is a merge blocker — no correctness bugs found in the flip logic itself, and the merge-order note (after #6709) is already called out in the PR body. |
norkans7
force-pushed
the
dev-n7/whatsapp-urn-flip
branch
2 times, most recently
from
July 7, 2026 13:24
f75d460 to
50da2be
Compare
Adds a flip_whatsapp_urns management command that flips existing contact URNs for contacts that have a bsuid URN: * whatsapp:<e164 digits> -> tel:+<e164 digits> (the phone identity) * bsuid:<CC.alphanumeric> -> whatsapp:<CC.alphanumeric> (the business-scoped id) Runs in id-ordered batches, skips rows whose target identity already exists for the org (scoping the lookup by org_id, and skipping a batch on a concurrent-write IntegrityError), reindexes flipped contacts, and is safe to re-run. When a contact's all-digit whatsapp URN duplicates a tel URN it already has, the whatsapp URN is redundant (the bsuid takes over the whatsapp slot), so its message/call/event references are moved onto the tel URN and it's dropped rather than left behind. URN.validate/format/normalize are updated so the whatsapp scheme holds either a phone number (legacy, still shown as a friendly phone number) or a business-scoped id, matching gocommon.
norkans7
force-pushed
the
dev-n7/whatsapp-urn-flip
branch
from
July 7, 2026 13:40
50da2be to
d4b5c34
Compare
Author
|
Replaced by #6727 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
Adds a
flip_whatsapp_urnsmanagement command (not a data migration) that flips existing contact URNs to the new scheme model, only for contacts that have absuidURN:whatsapp:<e164 digits>→tel:+<e164 digits>(the phone identity)bsuid:<CC.alphanumeric>→whatsapp:<CC.alphanumeric>(the business-scoped user id)Scoping to contacts with a bsuid means a contact reachable only by a plain
whatsapp:phone URN (no bsuid) is left untouched — we only migrate contacts that actually have a business-scoped id to take over thewhatsapp:slot.Dropping redundant whatsapp URNs
When a contact's all-digit
whatsapp:<digits>URN would collide with atel:+<digits>URN already on the same contact, that whatsapp URN is redundant (the BSUID is taking over thewhatsapp:slot). Rather than leaving it behind, the command moves itsMsg/Call/ChannelEventreferences onto the surviving tel URN and deletes it. Collisions with atel:URN on a different contact are left untouched.Batching, concurrency & re-runnability
org_idandidentity; if a concurrent write inserts a colliding identity between the check and the update, that batch is logged and skipped (the command is safe to re-run and retries it).modified_onon flipped contacts so the search indexer picks them up.URN model changes
URN.validate/URN.normalize: thewhatsappscheme now holds either a phone number (legacy) or a business-scoped id (CC.alphanumeric), matching gocommon (Accept business-scoped user IDs as WhatsApp URNs gocommon#218). The BSUID pattern is shared viaURN.BSUID_PATH_REGEX.URN.format: business-scoped whatsapp ids are shown as-is; legacy all-digit whatsapp paths still get friendly phone formatting.ContactURNgainsCONTENT_RELATIONS+has_content()/reassign_content_to(), centralising "what references a URN" (previously hardcoded inContact._full_release, now shared) so the command's reassign-then-delete uses the model.Why a command instead of a migration
Lets ops run and observe the flip deliberately (and re-run it) rather than having it fire implicitly during deploy.
Tests
temba/contacts/management/commands/tests.py— both flip directions; the "no bsuid → not flipped" scoping; whatsapp→tel and bsuid→whatsapp collision skips; dropping a redundant whatsapp URN and reassigning its message reference onto the tel URN; a multi-batch id-cursor test (patchedBATCH_SIZE) that would loop forever on a cursor regression; and a re-apply idempotency check. Plus updatedtest_urn.pyfor the new whatsapp validate/normalize/display semantics.🤖 Generated with Claude Code