@@ -236,6 +236,14 @@ async def _list_head(self) -> None:
236236
237237 # Update the cached data
238238 for request_data in response .get ('items' , []):
239+ # Due to https://github.com/apify/apify-core/blob/v0.1377.0/src/api/src/lib/request_queues/request_queue.ts#L53,
240+ # the list_head endpoint may return truncated fields for long requests (e.g., long URLs or unique keys).
241+ # If truncation is detected, fetch the full request data by its ID from the API.
242+ # This is a temporary workaround - the caching will be refactored to use request IDs instead of unique keys.
243+ # See https://github.com/apify/apify-sdk-python/issues/630 for details.
244+ if '[truncated]' in request_data ['uniqueKey' ] or '[truncated]' in request_data ['url' ]:
245+ request_data = await self ._api_client .get_request (request_id = request_data ['id' ]) # noqa: PLW2901
246+
239247 request = Request .model_validate (request_data )
240248
241249 if request .unique_key in self ._requests_in_progress :
@@ -248,15 +256,14 @@ async def _list_head(self) -> None:
248256 # Only fetch the request if we do not know it yet.
249257 if request .unique_key not in self ._requests_cache :
250258 request_id = unique_key_to_request_id (request .unique_key )
251- complete_request_data = await self ._api_client .get_request (request_id )
252-
253- if complete_request_data is not None :
254- request = Request .model_validate (complete_request_data )
255- self ._requests_cache [request .unique_key ] = request
256- else :
259+ if request_data is not None and request_id != request_data ['id' ]:
257260 logger .warning (
258- f'Could not fetch request data for unique_key=`{ request .unique_key } ` (id=`{ request_id } `)'
261+ f'Request ID mismatch: { request_id } != { request_data ["id" ]} , '
262+ 'this may cause unexpected behavior.'
259263 )
264+ full_request_data = await self ._api_client .get_request (request_id )
265+ request = Request .model_validate (full_request_data )
266+ self ._requests_cache [request .unique_key ] = request
260267
261268 # Add new requests to the end of the head, unless already present in head
262269 if request .unique_key not in self ._head_requests :
0 commit comments