tim_manger
10/04/2023, 1:35 AMclass Employees(LiveStream):
primary_keys = ["id"]
rest_method = "Get"
path = '/3/employees'
name = "Employees"
schema_filepath = SCHEMAS_DIR / "Employees_Schema.json"
def get_child_context(self, record: dict, context: dict) -> dict:
"""Return a context dictionary for child streams."""
return {
"Id": record["Id"],
}
class EmployeeDetails(EasiPayLiveStream):
primary_keys = ["id"]
rest_method = "Get"
path = '/3/EmployeeDetails/{Id}'
name = "EmployeeDetails"
parent_stream_type = Employees
schema_filepath = SCHEMAS_DIR / "EmployeeDetails_Schema.json"
I found the validate_response(response: Response) → None in the documentation but I have not been able to work out how to add this to my EmployeeDetails class.
Is it possible to add Countinue_On_Failure = True type option to the EmployeeDetails class?
So my code would look something like below
class EmployeeDetails(EasiPayLiveStream):
primary_keys = ["id"]
rest_method = "Get"
path = '/3/EmployeeDetails/{Id}'
name = "EmployeeDetails"
parent_stream_type = Employees
schema_filepath = SCHEMAS_DIR / "EmployeeDetails.json"
Countinue_On_Failure = True
Thanks you for any help
REgardsReuben (Matatika)
10/04/2023, 2:54 AMvalidate_response for the EmployeeDetails stream to not error on 404 Not Found - something like:
from http import HTTPStatus
from singer_sdk.exceptions import FatalAPIError
...
def validate_response(self, response):
try:
super().validate_response(response)
except FatalAPIError as e:
if response.status_code != HTTPStatus.NOT_FOUND:
raise e
You will also need to override parse_response to yield no records in the case of `404 Not Found`:
def parse_response(self, response):
yield from super().parse_response(response) if response.status_code != HTTPStatus.NOT_FOUND else ()tim_manger
10/04/2023, 2:59 AMReuben (Matatika)
10/04/2023, 3:02 AMEmployeeDetails stream in your streams.py.tim_manger
10/04/2023, 3:05 AMReuben (Matatika)
10/04/2023, 3:12 AMsuper calls in the overridden methods) if you are handling edge-case behaviour, in order to take advantage of the boilerplate and features the SDK provides. In this case, we still want to leverage the default validate_response and parse_response behaviour for all non-404 Not Found responses:
https://github.com/meltano/sdk/blob/b4f9ac59742300b00e77571156d432ce97df3c05/singer_sdk/streams/rest.py#L149-L195
https://github.com/meltano/sdk/blob/b4f9ac59742300b00e77571156d432ce97df3c05/singer_sdk/streams/rest.py#L583-L595tim_manger
10/05/2023, 11:01 PMtim_manger
10/05/2023, 11:32 PMReuben (Matatika)
10/06/2023, 2:02 AMparse_response correctly (unless I'm missing something).
def parse_response(self, response):
yield from super().parse_response(response) if response.status_code != HTTPStatus.NOT_FOUND else ()
Here, for all valid non-404 Not Found responses, the default implementation of parse_response is called - this extracts the records from the JSON response body at the JSONPath defined for the stream (this involves decoding JSON, which is probably where you saw that error come from). For 404 Not Found responses, the default implementation of parse_response is not called, and the method will yield from an empty generator (()) instead (i.e. no JSON decode).
This works due to the order of evaluation in conditional expressions.
Feel free to ignore this if you are happy with your own change. 🙂