Hi Ethan, this has been fixed in the 2.211.0 SDK version.
Answered
Why are NotFound objects not treated as TectonResponse objects?
For an extension, I am attempting to return a NotFound object as a response to an ajax call made on the frontend. This NotFound class inherits from the TectonResponse class, just like the Success , BadRequest , and InternalServerError classes. The issue that I am running into is that I am receiving an error when I attempt to return a NotFound object that reads: q2_sdk.core.exceptions.InvalidReturnType: Ajax target method must return a dictionary or TectonResponse . The relevant code that I am using is below:
from q2_sdk.models.tecton import TectonResponse, Success, NotFound, BadRequest, InternalServerError
@ajax
async def unlock_credentials(self) -> TectonResponse:
user_logon: UserLogonRow
user: UserRow
does_user_data_match_login = False
passed_ssn = str(self.form_fields.get('ssn'))
passed_last_name = (str(self.form_fields.get('lastName'))).rstrip()
passed_dob = str(self.form_fields.get('dob'))
passed_login_id = (str(self.form_fields.get('loginId'))).rstrip()
try:
user_logon = await self.db.user_logon.get_login_by_name(passed_login_id)
except Exception as ex:
return InternalServerError("An error was encountered.")
if not user_logon:
return NotFound() # NotFound call here
for logon in user_logon:
try:
if await self.is_existing_user_data(logon.UserID, passed_ssn, passed_last_name, passed_dob) is True:
does_user_data_match_login = True
user = (await self.db.user.get(logon.UserID))[0]
except Exception as ex:
return InternalServerError("An error was encountered.")
if does_user_data_match_login is False:
return NotFound() # NotFound call here
if self.is_user_disabled(user) is False:
response = await self.db.user_logon.unlock(passed_login_id)
return Success()
else:
return BadRequest(f"You are not authorized to unlock the provided login ID, '{passed_login_id}'.")
I am running the latest version of the SDK and the latest version of Tecton. I cannot find why my NotFound objects are not treated as TectonResponses during ajax calls.
145 Views
1
Answer
2 years ago
2 years ago
Tags
Thanks Ethan for the report. We have a merge request to correct this bug. We'll let you know once the fix is available.
— Jason Herbert 2 years ago