Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Chain writer failed due to
TypeError
Solution: Use `bytes` in memory everywhere. Not elegant but fixes the problem. --- The Chain writer task for Chain.ETH failed with the following stacktrace: ``` aleph-pyaleph-1 | 2024-01-29 14:09:32 [ERROR] aleph.chains.connector: Chain writer task for Chain.ETH failed, relaunching in 10 seconds. aleph-pyaleph-1 | Traceback (most recent call last): aleph-pyaleph-1 | File "/opt/pyaleph/src/aleph/chains/connector.py", line 63, in chain_writer_task aleph-pyaleph-1 | await connector.packer(config) aleph-pyaleph-1 | File "/opt/pyaleph/src/aleph/chains/ethereum.py", line 351, in packer aleph-pyaleph-1 | await self.chain_data_service.prepare_sync_event_payload( aleph-pyaleph-1 | File "/opt/pyaleph/src/aleph/chains/chain_data_service.py", line 75, in prepare_sync_event_payload aleph-pyaleph-1 | ipfs_cid = await self.storage_service.add_file( aleph-pyaleph-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aleph-pyaleph-1 | File "/opt/pyaleph/src/aleph/storage.py", line 293, in add_file aleph-pyaleph-1 | await self.add_file_content_to_local_storage( aleph-pyaleph-1 | File "/opt/pyaleph/src/aleph/storage.py", line 269, in add_file_content_to_local_storage aleph-pyaleph-1 | await self.storage_engine.write(filename=file_hash, content=file_content) aleph-pyaleph-1 | File "/opt/pyaleph/src/aleph/services/storage/fileystem_engine.py", line 26, in write aleph-pyaleph-1 | file_path.write_bytes(content) aleph-pyaleph-1 | File "/usr/lib/python3.11/pathlib.py", line 1066, in write_bytes aleph-pyaleph-1 | view = memoryview(data) aleph-pyaleph-1 | ^^^^^^^^^^^^^^^^ aleph-pyaleph-1 | TypeError: memoryview: a bytes-like object is required, not 'str' ``` It appears that a `StringIO` was passed to `aleph.storage.add_file(...)`, resulting in `file_content` being of type `str`, where the underlying function `aleph.services.storage.fileystem_engine.FileSystemStorageEngine.write` expects the type `bytes`. Solution: 1. Encode the `archive_content` in UTF-8 before adding it in the storage service. 2. Modify the type annotations accordingly 3. Modify the signature of `aleph.storage.StorageService.add_file` to expect `bytes` instead of any `IO` type.
- Loading branch information