list[list[tuple[str, BaseModel]]] not loading after save
Closed this issue · 1 comments
andreish commented
Hi ,
I have following model :
class Detection(BaseModel):
bbox : list[int]
other_bbox :list[int] | None = None
class InferenceResult(BaseModel):
pgn: str
detections : list[Detection]
class RegressionResults(BaseModel):
id : ObjectIdField| None = None
job_url : str | None = None
branch : str
commit_sha : str
baseline: bool | None = False
created_date : str| None = None
inference_results: list[list[tuple[str,InferenceResult]]]
...
class RegressionResultsRepository(AbstractRepository[RegressionResults]):
class Meta:
collection_name = 'results'
calling repo.save works but
repo.find_one_by({"commit_sha":commit_sha}) raise:
File "/srv/.venv/lib/python3.12/site-packages/pydantic_mongo/abstract_repository.py", line 99, in to_model_custom
return output_type.model_validate(data_copy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/.venv/lib/python3.12/site-packages/pydantic/main.py", line 509, in model_validate
return cls.__pydantic_validator__.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for RegressionResults
inference_results.0
Input should be a valid list [type=list_type, input_value={'pgn': '1. e4 e5 2. Nf3 ...diction_pos_to': 'd8'}]}, input_type=dict]
looking at what mongo gives back when calling pymongo api :
collection.find_one({"commit_sha":commit_sha})
one={
"_id": "65f95571d1c5642ed4a486ce",
"baseline": false,
"branch": "test",
"commit_sha": "abcdefgh",
"created_date": "2024-03-19T09:05:53.198436+00:00",
"inference_results": [
{
"detections": [
{
"bbox": [
195,
81,
193,
I was expecting to see :
one={
"_id": "65f95571d1c5642ed4a486ce",
"baseline": false,
"branch": "test",
"commit_sha": "abcdefgh",
"created_date": "2024-03-19T09:05:53.198436+00:00",
"inference_results": [ //list
[ //list
[ //tuple
{ //InferenceResult
"detections": [
{
"bbox": [
195,
81,
193,
Any idea on why this behaviour and how to fix?
using pydantic==2.6.4
pydantic-mongo==2.1.2
pydantic_core==2.16.3
pymongo==4.6.2
mongo runs in docker with image mongo:7.0.7-jammy
andreish commented
Fixed after dropping mongo data and restarted testing , possibly some itermediate model version was saved.