Skip to content

Add tel scheme support to WhatsApp channels and flip existing URNs#6703

Closed
norkans7 wants to merge 7 commits into
mainfrom
dev-n7/bsuid-whatsapp-flip
Closed

Add tel scheme support to WhatsApp channels and flip existing URNs#6703
norkans7 wants to merge 7 commits into
mainfrom
dev-n7/bsuid-whatsapp-flip

Conversation

@norkans7

@norkans7 norkans7 commented Jul 2, 2026

Copy link
Copy Markdown

WhatsApp channel types now support the tel scheme in addition to whatsapp, and enable international sending. Migration 0211 backfills tel scheme and allow_international onto existing whatsapp-scheme channels.

Migration 0217 flips existing contact URNs to the new scheme model: whatsapp -> tel (with leading +) and bsuid -> whatsapp, skipping rows that would collide with an existing URN and reindexing affected contacts.

@claude

claude Bot commented Jul 2, 2026

Copy link
Copy Markdown

Claude finished @norkans7's task in 5m 54s —— View job


Claude PR Review

  • Read the two new migrations (0211, 0217)
  • Read the channel-type/view changes
  • Read the migration test
  • Post findings

Summary

The channel-type side of the change (adding TEL_SCHEME to every WhatsApp-family channel type and setting allow_international=True on claim) is straightforward and looks correct. The data-migration side has a few things worth another look before merging.

Findings

  1. URN.validate / URN.format weren't updated for the new whatsapp: semantics. After 0217 runs, whatsapp: URNs hold BSUID-style paths (CC.alphanumeric), but temba/contacts/models.py:207-208 still requires the whatsapp path to match ^[0-9]+$, and temba/contacts/models.py:137-154 still prepends + and runs the path through phonenumbers.parse. Two concrete consequences:

    • validate_urn (temba/api/v2/fields.py:34) will reject any whatsapp:RW.abc123 submitted via API v2 for contact create/update — a functional regression the moment the migration runs.
    • URN.format('whatsapp:RW.abc123') returns '+RW.abc123'phonenumbers.parse raises NumberParseException, and the fallthrough return path returns the already-mutated (+-prefixed) path. Display code (ContactURN.get_display, temba/contacts/templatetags/contacts.py:66, temba/airtime/views.py, temba/orgs/models.py:1569) will render bogus leading + on every flipped BSUID.

    Either the whatsapp branches of validate/format need to move to the BSUID shape in this PR, or 0217 should wait until they do.

  2. 0217 runs an un-batched UPDATE over all whatsapp/bsuid rows in contacts_contacturn. The prior data migration (0215_fix_bad_last_seen_ons) batches in 1000-row chunks; for installs with large URN tables this one can hold long row locks and produce a huge single statement. See inline comment.

  3. Migration test doesn't cover the bsuid→whatsapp collision skip path. The whatsapp→tel collision case is covered by contact4; the symmetric bsuid→whatsapp collision case is not, so the NOT EXISTS in lines 50–53 of 0217 is untested. See inline comment.

  4. 0211_add_tel_scheme is entirely # pragma: no cover. It changes both schemes and a config default (allow_international=True) for every existing WhatsApp channel; a small MigrationTest is worth it. See inline comment.

  5. Minor: in 0217, the AND t.id <> u.id clause is dead — a row's own whatsapp: identity can never equal tel:+.... Noise, not a bug. See inline comment.
    • branch dev-n7/bsuid-whatsapp-flip

Comment thread temba/contacts/migrations/0217_flip_whatsapp_tel_urns.py Outdated
Comment thread temba/contacts/migrations/0217_flip_whatsapp_tel_urns.py Outdated
Comment thread temba/contacts/tests/test_migrations.py
Comment thread temba/channels/migrations/0211_add_tel_scheme.py Outdated
Comment thread temba/contacts/migrations/0217_flip_whatsapp_tel_urns.py Outdated
norkans7 added 2 commits July 7, 2026 10:02
WhatsApp channel types now support the tel scheme in addition to whatsapp,
and enable international sending. Migration 0211 backfills tel scheme and
allow_international onto existing whatsapp-scheme channels.

Migration 0217 flips existing contact URNs to the new scheme model:
whatsapp -> tel (with leading +) and bsuid -> whatsapp, skipping rows that
would collide with an existing URN and reindexing affected contacts.
@norkans7
norkans7 force-pushed the dev-n7/bsuid-whatsapp-flip branch from c87f16f to 006b6b6 Compare July 7, 2026 08:15
norkans7 added 5 commits July 7, 2026 10:25
…erage

- only flip all-digit whatsapp paths to tel, making 0217 safe to re-run
- cover the bsuid->whatsapp collision-skip path and re-apply idempotency
- add a MigrationTest for 0211_add_tel_scheme
… id semantics

After the flip, whatsapp URNs hold a business-scoped id (CC.alphanumeric)
rather than a phone number:
- validate whatsapp paths as the BSUID pattern instead of all-digits
- stop phone-formatting whatsapp in URN.format (was rendering a spurious +)
- uppercase the country code prefix when normalizing whatsapp paths
…s-scoped id

gocommon (PR #218) validates whatsapp paths as either all-digits (legacy
phone) or a business-scoped id (CC.alphanumeric). Match that here so the
Python and Go layers agree - notably for collision-skipped digit whatsapp
URNs the flip migration intentionally leaves in place.
… row

- hoist the BSUID path pattern into URN.BSUID_PATH_REGEX, referenced by both
  the whatsapp and bsuid branches of URN.validate (mirrors gocommon)
- in the flip migration, compute each row's target path/identity a single time
  instead of via a twice-evaluated closure
WhatsApp channels have no country set, so goflow's international-routing gate
(which only fires when the channel country differs from the destination) never
applies to them - setting allow_international was a no-op. Drop it from the
0211 migration and from every WhatsApp-family claim view; the tel scheme is
still added, and the update form still exposes the (default off) toggle.
@norkans7

norkans7 commented Jul 7, 2026

Copy link
Copy Markdown
Author

Split into two focused PRs: #6709 (add tel scheme support to WhatsApp channels) and #6710 (flip existing WhatsApp URNs to the new scheme model). #6710 should merge after #6709. Closing this combined PR in favor of those.

@norkans7 norkans7 closed this Jul 7, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2026
@norkans7
norkans7 deleted the dev-n7/bsuid-whatsapp-flip branch July 7, 2026 13:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant