instantiate ValidationError according to https://github.com/pydantic/pydantic/issues/6734

This commit is contained in:
sneakers-the-rat 2024-09-02 19:00:15 -07:00
parent ee35e5921b
commit 676d42d4f5
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
13 changed files with 130 additions and 39 deletions

View file

@ -279,7 +279,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -288,8 +288,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -524,7 +524,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -533,8 +533,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -524,7 +524,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -533,8 +533,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -524,7 +524,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -533,8 +533,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model

View file

@ -526,7 +526,7 @@ class DynamicTableMixin(BaseModel):
if isinstance(model, dict):
for key, val in model.items():
if key in cls.model_fields:
if key in cls.model_fields or key in cls.NON_COLUMN_FIELDS:
continue
if not isinstance(val, (VectorData, VectorIndex)):
try:
@ -535,8 +535,15 @@ class DynamicTableMixin(BaseModel):
else:
model[key] = VectorData(name=key, description="", value=val)
except ValidationError as e: # pragma: no cover
raise ValidationError(
f"field {key} cannot be cast to VectorData from {val}"
raise ValidationError.from_exception_data(
title=f"field {key} cannot be cast to VectorData from {val}",
line_errors=[
{
"type": "ValueError",
"loc": ("DynamicTableMixin", "cast_extra_columns"),
"input": val,
}
],
) from e
return model