You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes absolutely. The Json deserializer is not giving back a str but a dict on a model_dump()...
I may send a PR soon to fix this.
But when reading source there is this statement so I think this was a choice but I don't understand why...
class Json(BaseJson):
data: Serializable
def __init__(self, data: Serializable) -> None:
self.data = data
super().__init__()
@classmethod
def keys(cls, **data: Serializable) -> Json:
return cls(data)
if TYPE_CHECKING:
# Fields that are of the `Json` type are automatically
# de-serialized from json to the corresponding python type
# when the model is created, e.g.
#
# User(json_obj='{"foo": null}') -> User(json_obj={'foo': None})
#
# As we don't know what the type will actually be at runtime
# we add methods here for convenience so that naive access
# to the field is still allowed, e.g.
#
# user.json_obj['foo']
# user.json_obj[1]
# user.json_obj[1:5]
#
# It should be noted that users will still have
# to validate / cast fields to the type they are expecting
# for any strict type binding or nested index calls to work, e.g.
#
# isinstance(user.json_obj, dict)
# cast(Dict[str, Any], user.json_obj)
# prisma.validate(ExpectedType, user.json_obj) # NOTE: not implemented yet
Bug description
if we have model like following:
It will generate prisma model:
The problem is, the Json type result automatically de-serialize to a python obect.
For example:
'{"a":1}'
become a dict{'a': 1}
We would expect
Test.prisma(db).create(data=test.model_dump(mode='json'))
work without problem.However, it will not work, because during serialization the manifest does not serialize back to string. It keeps the dict type instead.
I think the correct behaviour should serialize the manifest back to Json string.
How to reproduce
Steps to reproduce the behavior:
Test.prisma().create(data=Test(id="1", manifest='{"a": 1}').model_dump(mode='json'))
Expected behavior
It should just work
Prisma information
Environment & setup
The text was updated successfully, but these errors were encountered: