MCPcopy Create free account
hub / github.com/tortoise/tortoise-orm / to_python_value

Method to_python_value

tortoise/fields/data.py:785–805  ·  view source on GitHub ↗
(
        self, value: T | str | bytes | dict | list | None
    )

Source from the content-addressed store, hash-verified

783 return self.encoder(value)
784
785 def to_python_value(
786 self, value: T | str | bytes | dict | list | None
787 ) -> T | dict | list | None:
788 if isinstance(value, (str, bytes)):
789 try:
790 data = self.decoder(value)
791 except Exception:
792 raise FieldError(
793 f"Value {value if isinstance(value, str) else value.decode()} is invalid json value."
794 )
795
796 if (
797 _PydanticModelMetaclass is not None
798 and isinstance(self.field_type, _PydanticModelMetaclass)
799 and not isinstance(data, list)
800 ):
801 return self.field_type(**data)
802
803 return data
804
805 return value
806
807
808class UUIDField(Field[T_UUID], UUID):

Callers

nothing calls this directly

Calls 1

FieldErrorClass · 0.90

Tested by

no test coverage detected