diff --git a/dlt/sources/rest_api/config_setup.py b/dlt/sources/rest_api/config_setup.py index 7659a01070..18d9546247 100644 --- a/dlt/sources/rest_api/config_setup.py +++ b/dlt/sources/rest_api/config_setup.py @@ -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 diff --git a/tests/sources/rest_api/conftest.py b/tests/sources/rest_api/conftest.py index 8ef4e41255..7f20dc2252 100644 --- a/tests/sources/rest_api/conftest.py +++ b/tests/sources/rest_api/conftest.py @@ -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") diff --git a/tests/sources/rest_api/integration/test_offline.py b/tests/sources/rest_api/integration/test_offline.py index 7fe77de029..4a917094d1 100644 --- a/tests/sources/rest_api/integration/test_offline.py +++ b/tests/sources/rest_api/integration/test_offline.py @@ -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: