Skip to content

Commit

Permalink
change parsing order
Browse files Browse the repository at this point in the history
  • Loading branch information
eavanvalkenburg committed Jan 6, 2025
1 parent 6200d81 commit d14f159
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,10 @@ def _serialize_data_model_to_dict(self, record: TModel, **kwargs: Any) -> OneOrM
"""
if self.data_model_definition.to_dict:
return self.data_model_definition.to_dict(record, **kwargs)
if isinstance(record, BaseModel):
return self._serialize_vectors(record.model_dump())
if isinstance(record, ToDictMethodProtocol):
return self._serialize_vectors(record.to_dict())
if isinstance(record, BaseModel):
return self._serialize_vectors(record.model_dump())

store_model = {}
for field_name in self.data_model_definition.field_names:
Expand Down Expand Up @@ -611,14 +611,14 @@ def _deserialize_dict_to_data_model(self, record: OneOrMany[dict[str, Any]], **k
"Cannot deserialize multiple records to a single record unless you are using a container."
)
record = record[0]
if issubclass(self.data_model_type, BaseModel):
if include_vectors:
record = self._deserialize_vector(record)
return self.data_model_type.model_validate(record) # type: ignore
if func := getattr(self.data_model_type, "from_dict", None):
if include_vectors:
record = self._deserialize_vector(record)
return func(record)
if issubclass(self.data_model_type, BaseModel):
if include_vectors:
record = self._deserialize_vector(record)
return self.data_model_type.model_validate(record) # type: ignore
data_model_dict: dict[str, Any] = {}
for field_name in self.data_model_definition.fields:
if not include_vectors and field_name in self.data_model_definition.vector_field_names:
Expand Down

0 comments on commit d14f159

Please sign in to comment.