Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/aleph/chains/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from enum import IntEnum
from typing import Dict, Optional, Tuple, List

from aleph_message.models import MessageType
from aleph_message.models import MessageType, ItemType
from bson import ObjectId
from pymongo import UpdateOne

Expand All @@ -28,6 +28,7 @@
from aleph.storage import get_json, pin_hash, add_json, get_message_content
from .tx_context import TxContext
from ..schemas.pending_messages import BasePendingMessage
from ..utils import item_type_from_hash

LOGGER = logging.getLogger("chains.common")

Expand Down Expand Up @@ -104,6 +105,23 @@ async def mark_message_for_retry(
LOGGER.debug(f"Update result {result}")


def update_message_item_type(message_dict: Dict) -> Dict:
"""
Ensures that the item_type field of a message is present.
Sets it to the default value if the field is not specified.
"""
if "item_type" in message_dict:
return message_dict

if "item_content" in message_dict:
item_type = ItemType.inline
else:
item_type = item_type_from_hash(message_dict["item_hash"])

message_dict["item_type"] = item_type
return message_dict


async def incoming(
message: Dict,
chain_name: Optional[str] = None,
Expand All @@ -120,6 +138,10 @@ async def incoming(
if existing in database, created if not.
"""

# 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 = update_message_item_type(message)

item_hash = message["item_hash"]
sender = message["sender"]
ids_key = (item_hash, sender, chain_name)
Expand Down
4 changes: 0 additions & 4 deletions src/aleph/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ 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