-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
phonenumbers.PhoneNumberMatcher does not correctly parse a phone number #108
Comments
@k-macmillan The python-phonenumbers maintainer gave me helpful information. Now I'm thinking we should go with options 2 or 3 (as enumerated above). The downside to 2 is that I'm not entirely certain what the behavior should be, so I'm unsure if I should address failing unit tests by changing the functionality or changing the tests. |
Concerning Option 3, here are the affected files in notifications-api: .../notification-api$ grep -r notifications_utils\.recipients .
./tests/app/celery/test_provider_tasks.py:from notifications_utils.recipients import InvalidEmailError
./tests/app/delivery/test_send_to_providers.py:from notifications_utils.recipients import validate_and_format_phone_number
./tests/app/notifications/test_process_notifications.py:from notifications_utils.recipients import validate_and_format_phone_number, validate_and_format_email_address
./tests/app/service/test_send_one_off_notification.py:from notifications_utils.recipients import InvalidPhoneError
./tests/app/clients/test_aws_ses.py:from notifications_utils.recipients import InvalidEmailError
./tests/app/clients/test_govdelivery_client.py:from notifications_utils.recipients import InvalidEmailError
./app/v2/errors.py:from notifications_utils.recipients import InvalidEmailError
./app/v2/notifications/post_notifications.py:from notifications_utils.recipients import try_validate_and_format_phone_number
./app/celery/provider_tasks.py:from notifications_utils.recipients import InvalidEmailError
./app/celery/tasks.py:from notifications_utils.recipients import (
./app/dao/notifications_dao.py:from notifications_utils.recipients import (
./app/schemas.py:from notifications_utils.recipients import (
./app/inbound_sms/rest.py:from notifications_utils.recipients import try_validate_and_format_phone_number
./app/delivery/send_to_providers.py:from notifications_utils.recipients import (
./app/errors.py:from notifications_utils.recipients import InvalidEmailError
./app/notifications/validators.py:from notifications_utils.recipients import (
./app/notifications/rest.py:from notifications_utils.recipients import get_international_phone_info
./app/notifications/receive_notifications.py:from notifications_utils.recipients import try_validate_and_format_phone_number
./app/notifications/process_notifications.py:from notifications_utils.recipients import (
./app/service/utils.py:from notifications_utils.recipients import allowed_to_send_to
./app/clients/email/aws_ses.py:from notifications_utils.recipients import InvalidEmailError
./app/clients/email/govdelivery_client.py:from notifications_utils.recipients import InvalidEmailError
./app/models.py:from notifications_utils.recipients import (
./app/schema_validation/__init__.py:from notifications_utils.recipients import (validate_phone_number, validate_email_address, InvalidPhoneError, I think my first choice is to write a short phone number validation function in notification-api/app/utils.py and remove the dependency on notifications_utils.recipients from notifications-api. |
I think we do need to roll our own. In this case we have several options. We can specify a list of characters to allow, using list comprehension so it is formatted. We could use We need to be as forgiving as possible. So if they give us all the numbers we rip out everything else and ensure there's a |
The number in question appears to not be a valid number, however (there is no 392 prefix in that area code). The benefit of using a library like this one is that it actually checks if the number is valid (assigned to an exchange) and not just if the number is possible (formatted as expected with the correct number of digits). I'd go with option 2 here, and fix the 8 unit tests. |
Removing high priority as it is no longer a functional bug |
phonenumbers.PhoneNumberMatcher calls is_possible_number and is_valid_number. The latter is what is raising errors for numbers like +17553927664. This is the correct functionality, but the error messages, including the one about international numbers, are misleading. The remaining work for this ticket should be to:
|
VeText was notified yesterday regarding the findings. Additional Info for those working this: |
An example of what the new return message could look like:
That way we don't have to really change any code or add logic. |
@k-macmillan, can you review, as I've made the changes you requested. |
Reviewed your draft @ianperera . Please remember to ping in slack. |
Deploy to dev and tested |
|
QA PASSES in PERF
Payload - for all future tests, only the phone_number changes
201 response from POST route
received text and in GET Notifications, the status updated to
|
The phone number +17553927664 is not correctly being parsed, which is causing errors downstream in notification-api. The problem seems to be that phonenumbers.PhoneNumberMatcher, which is called here, does not work as expected.
I opened a ticket in the python-phonenumbers repo, and the maintainer closed it with a useful comment. Please read the details there.
Possible mitigations:
The text was updated successfully, but these errors were encountered: