diff --git a/src/marqo/core/models/marqo_index_request.py b/src/marqo/core/models/marqo_index_request.py index eb9175b55..d4633b0f0 100644 --- a/src/marqo/core/models/marqo_index_request.py +++ b/src/marqo/core/models/marqo_index_request.py @@ -46,7 +46,7 @@ class FieldRequest(StrictBaseModel): features: List[marqo_index.FieldFeature] = [] dependent_fields: Optional[Dict[str, float]] = pydantic.Field(alias='dependentFields') - @root_validator + @root_validator(skip_on_failure=True) def check_all_fields(cls, values): marqo_index.validate_structured_field(values, marqo_index=False) diff --git a/tests/tensor_search/test_api.py b/tests/tensor_search/test_api.py index a8ed6d49c..4431485f8 100644 --- a/tests/tensor_search/test_api.py +++ b/tests/tensor_search/test_api.py @@ -241,3 +241,60 @@ def test_create_index_snake_case_fails(self): ) self.assertEqual(response.status_code, 200) + + def test_invalid_structured_index_field_type(self): + """Verify invalid field types are rejected with proper error""" + + base_index_settings = { + "type": "structured", + "allFields": [{"name": "field1", "type": None}], + "tensorFields": [] + } + + test_cases = [ + ("bulabua", "Invalid field type 'bulabua'"), + ([], "Invalid field type '[]'"), + (None, "Invalid field type 'NoneType'"), + ("", "Invalid field type ''"), + ] + + for test_case, test_name in test_cases: + test_settings = base_index_settings.copy() + test_settings["allFields"][0]["type"] = test_case + with self.subTest(test_name): + index_name = 'a' + str(uuid.uuid4()).replace('-', '') + response = self.client.post( + f"/indexes/{index_name}", + json=test_settings + ) + self.assertEqual(response.status_code, 422) + self.assertIn("allFields", response.text) + self.assertIn("type", response.text) + + def test_invalid_structured_index_field_features(self): + """Verify invalid field features are rejected with proper error""" + + base_index_settings = { + "type": "structured", + "allFields": [{"name": "field1", "type": "text", "features": None}], + "tensorFields": [] + } + + test_cases = [ + ("bulabua", "Invalid field feature 'bulabua'"), + (None, "Invalid field feature 'NoneType'"), + ("", "Invalid field feature ''"), + ] + + for test_case, test_name in test_cases: + test_settings = base_index_settings.copy() + test_settings["allFields"][0]["features"] = test_case + with self.subTest(test_name): + index_name = 'a' + str(uuid.uuid4()).replace('-', '') + response = self.client.post( + f"/indexes/{index_name}", + json=test_settings + ) + self.assertEqual(response.status_code, 422) + self.assertIn("allFields", response.text) + self.assertIn("features", response.text) \ No newline at end of file