Skip to content

Commit

Permalink
[Fix] Set default item_type in messages (#296)
Browse files Browse the repository at this point in the history
Fix for a regression in the message validation. If the user did
not specify the item type of the message, the default value was
not added to the message anymore, resulting in errors down
the line.
  • Loading branch information
odesenfans authored Jun 3, 2022
1 parent 991ef2b commit 9e685b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/aleph/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ async def check_message(

message = parse_message(message_dict)

# TODO: this is a temporary fix to set the item_type of the message to the correct
# value. This should be replaced by a full use of Pydantic models.
message_dict["item_type"] = message.item_type.value

if trusted:
# only in the case of a message programmatically built here
# from legacy native chain signing for example (signing offloaded)
Expand Down
4 changes: 2 additions & 2 deletions src/aleph/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from aleph.services.ipfs.storage import pin_add as ipfs_pin_add
from aleph.services.p2p.http import request_hash as p2p_http_request_hash
from aleph.services.p2p.singleton import get_streamer
from aleph.utils import get_sha256, run_in_executor
from aleph.utils import get_sha256, run_in_executor, item_type_from_hash

LOGGER = logging.getLogger("STORAGE")

Expand Down Expand Up @@ -67,7 +67,7 @@ async def json_async_loads(s: AnyStr):


async def get_message_content(message: Dict) -> MessageContent:
item_type: str = message.get("item_type", ItemType.ipfs)
item_type: str = message["item_type"]
item_hash = message["item_hash"]

if item_type in (ItemType.ipfs, ItemType.storage):
Expand Down

0 comments on commit 9e685b7

Please sign in to comment.