Skip to content

Commit

Permalink
Patch structured index type and features error (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliAlex authored Jan 31, 2024
1 parent 0c31fad commit 77f3c22
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/marqo/core/models/marqo_index_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
57 changes: 57 additions & 0 deletions tests/tensor_search/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 77f3c22

Please sign in to comment.