Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: change order used to check variants in (de)ser steps #10051

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading