Skip to content

Commit ab18831

Browse files
Python: change order used to check variants in (de)ser steps (#10051)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> While reviewing the docs, noticed some illogical behavior, this fixes that. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
1 parent 8751cbc commit ab18831

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

python/semantic_kernel/data/vector_storage/vector_store_record_collection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,10 @@ def _serialize_data_model_to_dict(self, record: TModel, **kwargs: Any) -> OneOrM
518518
"""
519519
if self.data_model_definition.to_dict:
520520
return self.data_model_definition.to_dict(record, **kwargs)
521-
if isinstance(record, BaseModel):
522-
return self._serialize_vectors(record.model_dump())
523521
if isinstance(record, ToDictMethodProtocol):
524522
return self._serialize_vectors(record.to_dict())
523+
if isinstance(record, BaseModel):
524+
return self._serialize_vectors(record.model_dump())
525525

526526
store_model = {}
527527
for field_name in self.data_model_definition.field_names:
@@ -611,14 +611,14 @@ def _deserialize_dict_to_data_model(self, record: OneOrMany[dict[str, Any]], **k
611611
"Cannot deserialize multiple records to a single record unless you are using a container."
612612
)
613613
record = record[0]
614-
if issubclass(self.data_model_type, BaseModel):
615-
if include_vectors:
616-
record = self._deserialize_vector(record)
617-
return self.data_model_type.model_validate(record) # type: ignore
618614
if func := getattr(self.data_model_type, "from_dict", None):
619615
if include_vectors:
620616
record = self._deserialize_vector(record)
621617
return func(record)
618+
if issubclass(self.data_model_type, BaseModel):
619+
if include_vectors:
620+
record = self._deserialize_vector(record)
621+
return self.data_model_type.model_validate(record) # type: ignore
622622
data_model_dict: dict[str, Any] = {}
623623
for field_name in self.data_model_definition.fields:
624624
if not include_vectors and field_name in self.data_model_definition.vector_field_names:

0 commit comments

Comments
 (0)