Repository: apify/crawlee-python
File: src/crawlee/storage_clients/_file_system/_request_queue_client.py (Python)

Code before:
        """Cache for is_empty result: None means unknown, True/False is cached state."""

        self._state = recoverable_state
        """Recoverable state to maintain request ordering, in-progress status, and handled status."""

    @override
    async def get_metadata(self) -> RequestQueueMetadata:
        return self._metadata

    @property
    def path_to_rq(self) -> Path:
        """The full path to the request queue directory."""
        return self._path_to_rq

    @property
    def path_to_metadata(self) -> Path:
        """The full path to the request queue metadata file."""
        return self.path_to_rq / METADATA_FILENAME

    @classmethod
    async def _create_recoverable_state(cls, id: str, configuration: Configuration) -> RecoverableState:
        async def kvs_factory() -> KeyValueStore:
            from crawlee.storage_clients import FileSystemStorageClient  # noqa: PLC0415 avoid circular import
            from crawlee.storages import KeyValueStore  # noqa: PLC0415 avoid circular import

            return await KeyValueStore.open(storage_client=FileSystemStorageClient(), configuration=configuration)

        return RecoverableState[RequestQueueState](
            default_state=RequestQueueState(),
            persist_state_key=f'__RQ_STATE_{id}',
            persist_state_kvs_factory=kvs_factory,
            persistence_enabled=True,
            logger=logger,
        )

    @classmethod
    async def open(
        cls,
        *,
        id: str | None,
        name: str | None,
        alias: str | None,
        configuration: Configuration,
    ) -> FileSystemRequestQueueClient:
        """Open or create a file system request queue client.

        This method attempts to open an existing request queue from the file system. If a queue with the specified
        ID or name exists, it loads the metadata and state from the stored files. If no existing queue is found,
        a new one is created.

        Args:

Review comment (bug):
Creating a fresh filesystem storage client to open a request queue feels _wrong_ - at this point, we can be pretty sure that another one already exists. Is there a specific reason to do this or is it just because you don't have access to the existing one?

Code after:
        """Cache for is_empty result: None means unknown, True/False is cached state."""

        self._state = recoverable_state
        """Recoverable state to maintain request ordering, in-progress status, and handled status."""

    @override
    async def get_metadata(self) -> RequestQueueMetadata:
        return self._metadata

    @property
    def path_to_rq(self) -> Path:
        """The full path to the request queue directory."""
        return self._path_to_rq

    @property
    def path_to_metadata(self) -> Path:
        """The full path to the request queue metadata file."""
        return self.path_to_rq / METADATA_FILENAME

    @classmethod
    async def _create_recoverable_state(cls, id: str, configuration: Configuration) -> RecoverableState:
        async def kvs_factory() -> KeyValueStore:
            from crawlee.storage_clients import FileSystemStorageClient  # noqa: PLC0415 avoid circular import
            from crawlee.storages import KeyValueStore  # noqa: PLC0415 avoid circular import

            return await KeyValueStore.open(storage_client=FileSystemStorageClient(), configuration=configuration)

        return RecoverableState[RequestQueueState](
            default_state=RequestQueueState(),
            persist_state_key=f'__RQ_STATE_{id}',
            persist_state_kvs_factory=kvs_factory,
            persistence_enabled=True,
            logger=logger,
        )

    @classmethod
    async def open(
        cls,
        *,
        id: str | None,
        name: str | None,
        alias: str | None,
        configuration: Configuration,
    ) -> Self:
        """Open or create a file system request queue client.

        This method attempts to open an existing request queue from the file system. If a queue with the specified
        ID or name exists, it loads the metadata and state from the stored files. If no existing queue is found,
        a new one is created.

        Args: