Skip to content

log every persist notification call for SMS notifications if a user t… - #4945

Open
rparke wants to merge 2 commits into
mainfrom
rp-add-carrier-code-check-to-phonenumber-validation
Open

log every persist notification call for SMS notifications if a user t…#4945
rparke wants to merge 2 commits into
mainfrom
rp-add-carrier-code-check-to-phonenumber-validation

Conversation

@rparke

@rparke rparke commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

…ries to send to a uk mobile number in the reserved range

Comment on lines +180 to +191
try:
number = PhoneNumber(strip_and_remove_obscure_whitespace(notification.to))
five_digit_prefix = str(number.number.national_number)[:5]
if number.is_uk_mobile_number() and number.get_carrier_info == "":
current_app.logger.info(
"Service %s tried to send to UK mobile number in reserved range. Prefix without leading zero: %s",
service.id,
five_digit_prefix,
extra={"service_id": service.id, "five_digit_prefix": five_digit_prefix},
)
except InvalidPhoneError:
current_app.logger.info("Could not parse number")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The try-except is mainly just extra caution. Nothing in the logging code should stop us creating the row as normal.


# if simulated create a Notification model to return but do not persist the Notification to the dB
if not simulated:
dao_create_notification(notification=notification, _autocommit=_autocommit)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could optionally get the notification_id returned to us from dao_create_notification and put that in the log message (removes the need for storing the prefix but does require some more manual effort cross referencing)

@rparke
rparke force-pushed the rp-add-carrier-code-check-to-phonenumber-validation branch from b5ab85a to debc30d Compare September 1, 2026 13:13
…ries to send to a uk mobile number in the reserved range
@rparke
rparke force-pushed the rp-add-carrier-code-check-to-phonenumber-validation branch from debc30d to 0f7b336 Compare September 1, 2026 13:13
@rparke
rparke marked this pull request as ready for review September 1, 2026 13:14
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