Skip to content

Conversation

Pijukatel
Copy link
Contributor

@Pijukatel Pijukatel commented Oct 16, 2025

Description

  • Cache requests in RQ implementations by id instead of unique_key due to the Apify platform truncating long unique_keys.

Issues

Testing

  • Added unit test

@github-actions github-actions bot added this to the 125th sprint - Tooling team milestone Oct 16, 2025
@github-actions github-actions bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Oct 16, 2025
@Pijukatel Pijukatel force-pushed the cache-by-request-id branch from 288e0b3 to d3dab06 Compare October 17, 2025 08:13
@Pijukatel Pijukatel force-pushed the cache-by-request-id branch from d3dab06 to 922a4c8 Compare October 17, 2025 08:32
@Pijukatel Pijukatel changed the title Draft fix: Cache requests in RQ implementations by id Oct 17, 2025
@Pijukatel Pijukatel force-pushed the cache-by-request-id branch from 59a33b1 to 4209d75 Compare October 17, 2025 12:36
@Pijukatel Pijukatel marked this pull request as ready for review October 17, 2025 12:37
@Pijukatel Pijukatel requested a review from vdusek October 17, 2025 12:37
Copy link
Contributor

@vdusek vdusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few comments

logger.debug(
'Cannot find a request from the beginning of queue, will be retried later',
extra={'nextRequestUniqueKey': next_unique_key},
extra={'nextRequestId': next_request_id},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why camelCase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can answer that question 😉 , I was just following the same pattern you started:
https://github.com/apify/apify-sdk-python/pull/470/files#diff-82643bb1c4a8c0e5e3b8044d2248476e4c8e36fbff7bf672cbacd10368e17357R314

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yeah... mistake on my part; so could you please fix it since you're updating it?

logger.debug(
'Request fetched from the beginning of queue was already handled',
extra={'nextRequestUniqueKey': next_unique_key},
extra={'nextRequestId': next_request_id},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why camelCase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

response = await self._api_client.get_request(unique_key_to_request_id(unique_key))
return await self._get_request_by_id(unique_key_to_request_id(unique_key))

async def _get_request_by_id(self, request_id: str) -> Request | None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reluctant to follow a formatting rule that is not enforced automatically by a tool. We do not even have a coding style defined, so how does one know what rule to follow? The code base is not compliant with the rule anyway. Cherry picking it randomly in some PR's is just annoying.

I will be happy to follow the rule as long as it is enforced by a tool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. it is common for IDEs to offer customizable method sorting to your liking, for example, in PyCharm
image

return self._requests_cache[unique_key]
return await self._get_request(id=unique_key_to_request_id(unique_key))

async def _get_request(self, id: str) -> Request | None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pijukatel Pijukatel requested a review from vdusek October 20, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apify RQ client list_head method returns truncated unique keys and URLs for long URLs

2 participants