Skip to content

Remove E.164 validation for optional phone fields - #121

Merged
AutumnQiu99 merged 2 commits into
mainfrom
autumn/autologin-422-error
Apr 26, 2026
Merged

AutumnQiu99 merged 2 commits into
mainfrom
autumn/autologin-422-error

Conversation

@AutumnQiu99

@AutumnQiu99 AutumnQiu99 commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Removes strict E.164 check from optional_phone() in backend/validators.py.
  • Prevents unnecessary 422 responses for optional phone input.
  • Preserves existing normalization behavior (trim + empty => None).

Test plan

  • Submit request with phone omitted → succeeds
  • Submit request with phone: "" / whitespace → treated as None, succeeds
  • Submit request with non-E.164 phone (e.g. "4125551234") → no 422 from validator
  • Submit request with E.164 phone (e.g. "+14125551234") → still succeeds

Closes #120

@AutumnQiu99
AutumnQiu99 requested a review from gekiclaws April 25, 2026 19:04

@gekiclaws gekiclaws left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good fix for allowing Optix phone data to save. Since Optix gives us phone as a naive string, I agree we shouldn’t reject the whole user payload just because it isn’t E.164.

The remaining issue is that phone is currently doing double duty as both raw profile data and an SMS-sendable destination. We should allow optional_phone() to store the raw trimmed string, but SMS preference/send logic should only consider the phone valid if it is actually sendable, likely E.164 for now.

Concretely, I think optional_phone() can stay permissive, but normalize_effective_notification_state() should distinguish hasPhone from hasSmsPhone, or at least require E.164 before allowing "text" in notifPrefs. Otherwise a naive Optix value like "4125551234" can be saved and may let SMS notifications get enabled, only to fail later when Twilio receives it.

…preferences

- Introduced `is_e164_phone` function to validate phone numbers in E.164 format.
- Updated user preferences and member service to include `hasSmsPhone` flag.
- Enhanced SMS channel to skip sending messages for invalid phone numbers.
- Modified tests to cover new validation logic and preferences handling.
@AutumnQiu99

Copy link
Copy Markdown
Contributor Author

Added hasSmsPhone field, whose value is determined by is_e164_phone

@AutumnQiu99
AutumnQiu99 requested a review from gekiclaws April 26, 2026 00:38
@AutumnQiu99
AutumnQiu99 merged commit 19cac9f into main Apr 26, 2026
7 checks passed
@AutumnQiu99
AutumnQiu99 deleted the autumn/autologin-422-error branch April 26, 2026 15:02
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.

Optional phone number validation returns 422 for non-E.164 values

2 participants