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

Fix/1849 Do Not Parse Ignored Empty Responses #1851

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dlt/sources/rest_api/config_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ def response_action_hook(response: Response, *args: Any, **kwargs: Any) -> None:
hook(response)
elif action_type == "ignore":
logger.info(
f"Ignoring response with code {response.status_code} "
f"and content '{response.json()}'."
f"Ignoring response with code {response.status_code} and content '{response.text}'."
)
raise IgnoreResponseException

Expand Down
10 changes: 10 additions & 0 deletions tests/sources/rest_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ def post_detail_404(request, context):
context.status_code = 404
return {"error": "Post not found"}

@router.get(r"/posts/\d+/some_details_204")
def post_detail_204(request, context):
"""Return 204 No Content for post with id > 0. Used to test ignoring 204 responses."""
post_id = int(request.url.split("/")[-2])
if post_id < 1:
return {"id": post_id, "body": f"Post body {post_id}"}
else:
context.status_code = 204
return None

@router.get(r"/posts_under_a_different_key$")
def posts_with_results_key(request, context):
return paginate_by_page_number(request, generate_posts(), records_key="many-results")
Expand Down
40 changes: 40 additions & 0 deletions tests/sources/rest_api/integration/test_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,46 @@ def test_ignoring_endpoint_returning_404(mock_api_server):
]


def test_ignoring_endpoint_returning_204(mock_api_server):
mock_source = rest_api_source(
{
"client": {"base_url": "https://api.example.com"},
"resources": [
"posts",
{
"name": "post_details",
"endpoint": {
"path": "posts/{post_id}/some_details_204",
"params": {
"post_id": {
"type": "resolve",
"resource": "posts",
"field": "id",
}
},
"response_actions": [
{
"status_code": 204,
"action": "ignore",
},
],
},
},
],
}
)

res = list(mock_source.with_resources("posts", "post_details").add_limit(1))

assert res[:5] == [
{"id": 0, "body": "Post body 0"},
{"id": 0, "title": "Post 0"},
{"id": 1, "title": "Post 1"},
{"id": 2, "title": "Post 2"},
{"id": 3, "title": "Post 3"},
]


def test_source_with_post_request(mock_api_server):
class JSONBodyPageCursorPaginator(BaseReferencePaginator):
def update_state(self, response: Response, data: Optional[List[Any]] = None) -> None:
Expand Down
Loading