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
Seems like this part of the conversion (in the from_pydantic_model() method) might be based on an assumption that does not always hold:
eliff_name=='blob':
# here is a dirty fishy itchy trick# the original bytes will be encoded two times:# first time is real during `to_dict/to_json`, it converts into base64 string# second time is at `from_dict/from_json`, it is unnecessary yet inevitable, the result string get# converted into a binary string and encoded again.# consequently, we need to decode two times here!fields[f_name] =base64.b64decode(base64.b64decode(value))
My guess is that the blob is actually only encoded once, but it tries to decode twice, giving the error above.
Related Issue
The .dict() method of PydanticDocument does not implement any decoding of blob, but I think it should:
>>>d=Document(blob=b'hello')
>>>d.blobb'hello'>>>d_pyd=d.to_pydantic_model() # encodes the blob>>>d_pyd.blob'aGVsbG8='>>>d_pyd.dict()['blob'] # I think this should decode the blob and return b'hello''aGVsbG8='
@JoanFM I believe that if this behaviour of .dict() is fixed then the trick in the core of creating a DocumentArray becomes unnecessary.
The text was updated successfully, but these errors were encountered:
Problem description:
The class methods
to_pydantic_model()
/from_pydantic_model()
do not appear to be inverses of each other.How to reproduce:
Seems like this part of the conversion (in the
from_pydantic_model()
method) might be based on an assumption that does not always hold:My guess is that the
blob
is actually only encoded once, but it tries to decode twice, giving the error above.Related Issue
The
.dict()
method ofPydanticDocument
does not implement any decoding ofblob
, but I think it should:@JoanFM I believe that if this behaviour of
.dict()
is fixed then the trick in the core of creating aDocumentArray
becomes unnecessary.The text was updated successfully, but these errors were encountered: