mashumaro's JSONCodec cannot automatically serialize fields named "schema" of type Optional[str] when the class also derives from a JSON schema base (like dbt's JsonObjectSchema). The conflict arises because "schema" is a reserved keyword in the JSON Schema specification — mashumaro's introspection treats it as a schema descriptor rather than a plain string field.
Annotate the field with a pass-through SerializationStrategy to tell mashumaro to treat it as a plain string.
from dataclasses import dataclass, field
from typing import Optional
from mashumaro import DataClassJSONMixin
from mashumaro.types import SerializationStrategy
class StrPassthrough(SerializationStrategy):
def serialize(self, value: Optional[str]) -> Optional[str]:
return value
def deserialize(self, value: Optional[str]) -> Optional[str]:
return value
@dataclass
class JsonObjectSchema(DataClassJSONMixin):
schema: Optional[str] = field(
default=None,
metadata={"serialize": StrPassthrough()}
)If the error is coming from a dependency like dbt-core, pinning mashumaro can unblock you while waiting for an upstream fix.
pip install "mashumaro<3.0"