-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[low-code] convert request.body to a dict when converting to AirbyteLogMessage #20557
Conversation
@@ -408,20 +408,34 @@ def state(self, value: StreamState): | |||
def parse_records_and_emit_request_and_responses(self, request, response, stream_slice, stream_state) -> Iterable[StreamData]: | |||
# Only emit requests and responses when running in debug mode | |||
if self.logger.isEnabledFor(logging.DEBUG): | |||
yield self._create_trace_message_from_request(request) | |||
yield self._create_trace_message_from_response(response) | |||
yield prepared_request_to_airbyte_message(request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename
"url": request.url, | ||
"http_method": request.method, | ||
"headers": dict(request.headers), | ||
"body": _body_binary_string_to_dict(request.body), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of assigning the body directly, delegate to_body_binary_string_to_dict
to convert it to an Optional[Mapping]
@@ -155,6 +155,7 @@ def test_read_stream(): | |||
request = { | |||
"url": "https://demonslayers.com/api/v1/hashiras?era=taisho", | |||
"headers": {"Content-Type": "application/json"}, | |||
"http_method": "GET", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll be able to merge this PR when this is merged in so CI fails on broken tests #20217
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out - was looking into it for a PR I'm working on right now 😅
@@ -409,6 +422,11 @@ def test_read_stream_returns_error_if_stream_does_not_exist(): | |||
HttpRequest(url="https://nichirin.com/v1/swords", headers={"field": "name"}, body={"key": "value"}, http_method="PUT"), | |||
id="test_create_request_with_no_parameters", | |||
), | |||
pytest.param( | |||
'request:{"url": "https://nichirin.com/v1/swords", "http_method": "POST", "headers": {"field": "name"}, "body":null}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a test where "body": null
for peace of mind
return None | ||
|
||
|
||
def response_to_airbyte_message(response: requests.Response) -> AirbyteMessage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to a function for consistency and ease of testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those methods aren't used anywhere else except from the tests though. Should we indicate them as private using the _
prefix?
Saying that makes me think it is weird that parse_records_and_emit_request_and_responses
is public as well since it's only used internally by the class. My main concern is that we have someone external using it which would bring a dependency to manage when we want to change this. This happened for #20019 and prevented us to do a breaking change we wanted to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call. prepended both with _
return AirbyteMessage(type=MessageType.LOG, log=AirbyteLogMessage(level=Level.INFO, message=log_message)) | ||
|
||
def prepared_request_to_airbyte_message(request: requests.PreparedRequest) -> AirbyteMessage: | ||
# FIXME: this should return some sort of trace message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to keep them FIXMEs for now 😞
return AirbyteMessage(type=MessageType.LOG, log=AirbyteLogMessage(level=Level.INFO, message=log_message)) | ||
|
||
|
||
def _body_binary_string_to_dict(body_str) -> Optional[Mapping[str, str]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have typing for this parameter?
return None | ||
|
||
|
||
def response_to_airbyte_message(response: requests.Response) -> AirbyteMessage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those methods aren't used anywhere else except from the tests though. Should we indicate them as private using the _
prefix?
Saying that makes me think it is weird that parse_records_and_emit_request_and_responses
is public as well since it's only used internally by the class. My main concern is that we have someone external using it which would bring a dependency to manage when we want to change this. This happened for #20019 and prevented us to do a breaking change we wanted to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (pending resolution of Maxime's comments) @girarda!
raise HTTPException(status_code=400, detail=f"Could not perform read with with error: {error.args[0]}") | ||
raise HTTPException( | ||
status_code=400, | ||
detail=f"Could not perform read with with error: {error.args[0]}\n{''.join(traceback.TracebackException.from_exception(error).format())}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flash1293 FYI you can rebase from this branch if you need the stacktraces. will merge in after the holidays
What
SimpleRetriever
sends the request body as a string while the server expects it to be a mapHow
"k1=v1&k2=v"
Recommended reading order
airbyte-cdk/python/airbyte_cdk/sources/declarative/retrievers/simple_retriever.py
airbyte-cdk/python/unit_tests/sources/declarative/retrievers/test_simple_retriever.py
airbyte-connector-builder-server/unit_tests/connector_builder/impl/test_default_api.py
🚨 User Impact 🚨
Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changesTests
Unit
Put your unit tests output here.
Integration
Put your integration tests output here.
Acceptance
Put your acceptance tests output here.