From 676d42d4f5fd9e04e85ae5a929137a46ff5dbe7c Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 2 Sep 2024 19:00:15 -0700 Subject: [PATCH] instantiate ValidationError according to https://github.com/pydantic/pydantic/issues/6734 --- nwb_linkml/src/nwb_linkml/includes/hdmf.py | 13 ++++++++++--- .../hdmf_common/v1_1_0/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_1_2/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_1_3/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_2_0/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_2_1/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_3_0/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_4_0/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_5_0/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_5_1/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_6_0/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_7_0/hdmf_common_table.py | 13 ++++++++++--- .../hdmf_common/v1_8_0/hdmf_common_table.py | 13 ++++++++++--- 13 files changed, 130 insertions(+), 39 deletions(-) diff --git a/nwb_linkml/src/nwb_linkml/includes/hdmf.py b/nwb_linkml/src/nwb_linkml/includes/hdmf.py index 32efac4..631ad67 100644 --- a/nwb_linkml/src/nwb_linkml/includes/hdmf.py +++ b/nwb_linkml/src/nwb_linkml/includes/hdmf.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py index 66f21bc..f1ee937 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py index 5819917..6d78742 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py index 6637383..b7aabf3 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py index 8c14df1..5d66a65 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py index b6603e5..c319712 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py index 733b65a..a6e652d 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py index 8800d3d..3e947f4 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py index d23050d..a77379b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py index acfc173..8066977 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py index 0f76e29..3589ee4 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py index b7604f4..c5c62cf 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py @@ -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 diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py index 3cead40..7ed76ee 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py @@ -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