Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
 
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.

1

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
Votes Newest

Answers


Hi Ethan, this has been fixed in the 2.211.0 SDK version.

Posted 2 years ago
Jason Herbert
104 × 1 Administrator
144 Views
1 Answer
2 years ago
2 years ago
Tags