Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore instead of forbid extra fields #89

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions aleph_message/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
class UnknownHashError(ValueError):
...
class UnknownHashError(ValueError): ...
29 changes: 2 additions & 27 deletions aleph_message/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from pathlib import Path
from typing import Any, Dict, List, Literal, Optional, Type, TypeVar, Union, cast

from pydantic import BaseModel, Extra, Field, validator
from pydantic import BaseModel, Field, validator
from typing_extensions import TypeAlias

from .abstract import BaseContent
from .base import Chain, HashType, MessageType
from .execution.base import MachineType, Payment, PaymentType # noqa
from .execution.instance import InstanceContent
from .execution.program import ProgramContent
from .execution.base import PaymentType, MachineType, Payment # noqa
from .item_hash import ItemHash, ItemType


Expand All @@ -22,9 +22,6 @@ class MongodbId(BaseModel):

oid: str = Field(alias="$oid")

class Config:
extra = Extra.forbid


class ChainRef(BaseModel):
"""Some POST messages have a 'ref' field referencing other content"""
Expand All @@ -44,9 +41,6 @@ class MessageConfirmationHash(BaseModel):
binary: str = Field(alias="$binary")
type: str = Field(alias="$type")

class Config:
extra = Extra.forbid


class MessageConfirmation(BaseModel):
"""Format of the result when a message has been confirmed on a blockchain"""
Expand All @@ -61,16 +55,10 @@ class MessageConfirmation(BaseModel):
default=None, description="The address that published the transaction."
)

class Config:
extra = Extra.forbid


class AggregateContentKey(BaseModel):
name: str

class Config:
extra = Extra.forbid


class PostContent(BaseContent):
"""Content of a POST message"""
Expand All @@ -92,9 +80,6 @@ def check_type(cls, v, values):
raise ValueError("A 'ref' is required for POST type 'amend'")
return v

class Config:
extra = Extra.forbid


class AggregateContent(BaseContent):
"""Content of an AGGREGATE message"""
Expand All @@ -104,9 +89,6 @@ class AggregateContent(BaseContent):
)
content: Dict = Field(description="The content of an aggregate must be a dict")

class Config:
extra = Extra.forbid


class StoreContent(BaseContent):
"""Content of a STORE message"""
Expand All @@ -118,9 +100,6 @@ class StoreContent(BaseContent):
ref: Optional[str] = None
metadata: Optional[Dict[str, Any]] = Field(description="Metadata of the VM")

class Config:
extra = Extra.allow


class ForgetContent(BaseContent):
"""Content of a FORGET message"""
Expand Down Expand Up @@ -238,7 +217,6 @@ def convert_float_to_datetime(cls, v, values):
return v

class Config:
extra = Extra.forbid
exclude = {"id_", "_id"}


Expand Down Expand Up @@ -403,6 +381,3 @@ class MessagesResponse(BaseModel):
pagination_total: int
pagination_per_page: int
pagination_item: str

class Config:
extra = Extra.forbid
5 changes: 1 addition & 4 deletions aleph_message/models/abstract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Extra
from pydantic import BaseModel


def hashable(obj):
Expand All @@ -23,6 +23,3 @@ class BaseContent(BaseModel):

address: str
time: float

class Config:
extra = Extra.forbid
8 changes: 2 additions & 6 deletions aleph_message/models/execution/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

from pydantic import Field

from .environment import (
FunctionEnvironment,
HostRequirements,
MachineResources,
)
from ..abstract import BaseContent, HashableModel
from .base import Payment
from .environment import FunctionEnvironment, HostRequirements, MachineResources
from .volume import MachineVolume
from ..abstract import BaseContent, HashableModel


class BaseExecutableContent(HashableModel, BaseContent, ABC):
Expand Down
9 changes: 0 additions & 9 deletions aleph_message/models/execution/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class FunctionTriggers(HashableModel):
description="Persist the execution of the program instead of running it on demand.",
)

class Config:
extra = Extra.forbid


class NetworkProtocol(str, Enum):
tcp = "tcp"
Expand Down Expand Up @@ -78,9 +75,6 @@ class CpuProperties(HashableModel):
default=None, description="CPU vendor. Allows other vendors."
)

class Config:
extra = Extra.forbid


class HypervisorType(str, Enum):
qemu = "qemu"
Expand All @@ -101,9 +95,6 @@ class NodeRequirements(HashableModel):
default=None, description="Node address must match this regular expression"
)

class Config:
extra = Extra.forbid


class HostRequirements(HashableModel):
cpu: Optional[CpuProperties] = Field(
Expand Down
5 changes: 3 additions & 2 deletions aleph_message/models/execution/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class AbstractVolume(HashableModel, ABC):
mount: Optional[str] = None

@abstractmethod
def is_read_only(self):
...
def is_read_only(self): ...

class Config:
# This is the only type where we really need to forbid extra fields.
# Otherwise the pydantic_encoder will take the first allowed type instead of the correct one.
extra = Extra.forbid


Expand Down
Loading