Skip to content

feat: [Small Rock] Normalize phone values before persistence and uniqueness checks (Closes #163) - #241

Open
Moon-dg wants to merge 2 commits into
oss-slu:mainfrom
Moon-dg:feature-163-phone-normalization
Open

Moon-dg wants to merge 2 commits into
oss-slu:mainfrom
Moon-dg:feature-163-phone-normalization

Conversation

@Moon-dg

@Moon-dg Moon-dg commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Implemented backend canonical phone number normalization before database persistence and uniqueness checks under Big Rock [Big Rock] Establish account onboarding and data-quality foundations #144.
  • Strips non-digit characters (preserving the leading + for international country codes) in UserCreate Pydantic model to guarantee strict uniqueness and prevent duplicate accounts created via varied formatting.

Changes Made

  • backend/src/models.py:
    • Added import re at file level.
    • Added @field_validator('phone', mode='after') with normalize_phone to sanitize phone strings using re.sub(r'(?!^\+)\D', '', v).
    • Ensures clean E.164 phone values are stored and indexed in MongoDB.

Testing Details

  • Verified regular expression logic against international inputs (+1 234-567-8901 -> +12345678901).
  • Confirmed backward compatibility and uniqueness constraint mapping with existing user model indices.

Checklist

  • Canonical phone values are stored and indexed.
  • Formatting variations cannot bypass uniqueness.
  • All data sanitation logic is covered before persistence.

Closes #163

@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@mudabs mudabs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Moon, for adding backend phone normalization.

Please address these items before approval:

  1. Run normalization before pattern validation. With mode='after', formatted values such as +1 234-567-8901 are rejected before normalization runs.
  2. Apply the same normalization to UserUpdate and the profile update endpoint before duplicate checks and persistence.
  3. Add collision detection for existing formatted records and document the migration and rollback plan. The current unique index only protects exact stored strings.
  4. Add tests for formatted input, normalized duplicates, profile updates, canonical values, and invalid values.
  5. Re-run the full CI workflow. The current CI run requires action and has no jobs, so only SonarCloud is verified.

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.

[Small Rock] Normalize phone values before persistence and uniqueness checks

2 participants