Skip to content
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

Correctly await sendSMS #413

Merged
merged 3 commits into from Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/413.bugfix
@@ -0,0 +1 @@
Fix a long-standing bug in asynchronous code that could cause SMS messages not to be correctly sent.
8 changes: 4 additions & 4 deletions sydent/http/servlets/msisdnservlet.py
Expand Up @@ -21,7 +21,7 @@
from twisted.web.server import Request

from sydent.http.auth import authV2
from sydent.http.servlets import get_args, jsonwrap, send_cors
from sydent.http.servlets import asyncjsonwrap, get_args, jsonwrap, send_cors
from sydent.types import JsonDict
from sydent.util.stringutils import is_valid_client_secret
from sydent.validators import (
Expand All @@ -45,8 +45,8 @@ def __init__(self, syd: "Sydent", require_auth: bool = False) -> None:
self.sydent = syd
self.require_auth = require_auth

@jsonwrap
def render_POST(self, request: Request) -> JsonDict:
@asyncjsonwrap
async def render_POST(self, request: Request) -> JsonDict:
send_cors(request)

if self.require_auth:
Expand Down Expand Up @@ -90,7 +90,7 @@ def render_POST(self, request: Request) -> JsonDict:

brand = self.sydent.brand_from_request(request)
try:
sid = self.sydent.validators.msisdn.requestToken(
sid = await self.sydent.validators.msisdn.requestToken(
phone_number_object, clientSecret, sendAttempt, brand
)
resp = {
Expand Down
4 changes: 2 additions & 2 deletions sydent/validators/msisdnvalidator.py
Expand Up @@ -72,7 +72,7 @@ def __init__(self, sydent: "Sydent") -> None:

self.smsRules[country] = action

def requestToken(
async def requestToken(
self,
phoneNumber: phonenumbers.PhoneNumber,
clientSecret: str,
Expand Down Expand Up @@ -128,7 +128,7 @@ def requestToken(

smsBody = smsBodyTemplate.format(token=valSession.token)

self.omSms.sendTextSMS(smsBody, msisdn, originator)
await self.omSms.sendTextSMS(smsBody, msisdn, originator)

valSessionStore.setSendAttemptNumber(valSession.id, sendAttempt)

Expand Down