Skip to content

fix: backfill utm_source from legacy source column on Lead/Opportunity#396

Open
dpk404 wants to merge 2 commits into
version-16-hotfixfrom
backfill-utm-source-hotfix
Open

fix: backfill utm_source from legacy source column on Lead/Opportunity#396
dpk404 wants to merge 2 commits into
version-16-hotfixfrom
backfill-utm-source-hotfix

Conversation

@dpk404
Copy link
Copy Markdown
Collaborator

@dpk404 dpk404 commented May 22, 2026

Summary

Backport of 7fc3f44 to version-16-hotfix so the UTM-source backfill patch is available on the hotfix line.

Adds next_crm/patches/v1_0/backfill_utm_source_from_legacy_source.py and registers it in patches.txt (in addition to the existing v0_1.remove_stale_field_order_property_setters patch that's already on the hotfix branch).

Test plan

  • bench --site <site> migrate runs the patch without error
  • Confirm utm_source is populated for rows where it was previously NULL and the legacy source column had a value

dpk404 added 2 commits May 22, 2026 08:19
Ports frappe/erpnext#55022 so next_crm sites can
recover orphaned source values without waiting on the upstream patch to
land.

The v15 `migrate_to_utm_analytics` patch renamed `source -> utm_source`
on Lead and Opportunity via the `oldfieldname` schema hint. That hint
is documentation-only — Frappe's DocField sync never issues a
RENAME COLUMN based on it (only the desk-driven Custom Field rename
flow does). So on every upgraded site, `utm_source` was added as an
empty column and every row's data stayed on the legacy `source` column,
where get_meta()-aware code can't see it.

This patch:
- Skips cleanly if either column is absent (clean rename or fresh site).
- Copies legacy `source` -> `utm_source` for rows where utm is empty.
- Leaves rows with both columns populated to *different* values
  untouched and reports a count for manual triage.
- Idempotent — a second run is a no-op.

Reports per-doctype row counts on stdout during `bench migrate`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant