Skip to content

Commit

Permalink
fix: Resolve failing tests after pydantic V2 merge (#5700)
Browse files Browse the repository at this point in the history
# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

This PR resolves failing tests after pydantic V2 upgrade:

- Changes the expected error details
- Catch TypeError exception inside validator to resolve as a 422 status
response

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->

- Bug fix (non-breaking change which fixes an issue)

**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
  • Loading branch information
frascuchon authored Nov 20, 2024
1 parent 9cf0a63 commit 1c8f528
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
2 changes: 2 additions & 0 deletions argilla-server/src/argilla_server/api/schemas/v1/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def validate_chat_field_content(cls, fields: Any):
fields[key] = [
item if isinstance(item, ChatFieldValue) else ChatFieldValue(**item) for item in value
]
except TypeError as e:
raise ValueError(f"Error parsing chat field '{key}': {e}")
except ValidationError as e:
raise ValueError(f"Error parsing chat field '{key}': {e.errors()}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,19 +744,19 @@ async def test_create_dataset_records_bulk_with_wrong_custom_field_value(
"params": {
"errors": [
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "str type expected",
"type": "type_error.str",
"loc": ["body", "items", 0, "fields", "text-field", "constrained-str"],
"msg": "Input should be a valid string",
"type": "string_type",
},
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "value is not a valid list",
"type": "type_error.list",
"loc": ["body", "items", 0, "fields", "text-field", "list[ChatFieldValue]"],
"msg": "Input should be a valid list",
"type": "list_type",
},
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
"loc": ["body", "items", 0, "fields", "text-field", "dict[constrained-str,any]"],
"msg": "Input should be a valid dictionary",
"type": "dict_type",
},
]
},
Expand All @@ -771,19 +771,19 @@ async def test_create_dataset_records_bulk_with_wrong_custom_field_value(
"params": {
"errors": [
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "str type expected",
"type": "type_error.str",
"loc": ["body", "items", 0, "fields", "text-field", "constrained-str"],
"msg": "Input should be a valid string",
"type": "string_type",
},
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "value is not a valid list",
"type": "type_error.list",
"loc": ["body", "items", 0, "fields", "text-field", "list[ChatFieldValue]"],
"msg": "Input should be a valid list",
"type": "list_type",
},
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
"loc": ["body", "items", 0, "fields", "text-field", "dict[constrained-str,any]"],
"msg": "Input should be a valid dictionary",
"type": "dict_type",
},
]
},
Expand All @@ -798,19 +798,19 @@ async def test_create_dataset_records_bulk_with_wrong_custom_field_value(
"params": {
"errors": [
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "str type expected",
"type": "type_error.str",
"loc": ["body", "items", 0, "fields", "text-field", "constrained-str"],
"msg": "Input should be a valid string",
"type": "string_type",
},
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "value is not a valid list",
"type": "type_error.list",
"loc": ["body", "items", 0, "fields", "text-field", "list[ChatFieldValue]"],
"msg": "Input should be a valid list",
"type": "list_type",
},
{
"loc": ["body", "items", 0, "fields", "text-field"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
"loc": ["body", "items", 0, "fields", "text-field", "dict[constrained-str,any]"],
"msg": "Input should be a valid dictionary",
"type": "dict_type",
},
]
},
Expand All @@ -826,8 +826,10 @@ async def test_create_dataset_records_bulk_with_wrong_custom_field_value(
"errors": [
{
"loc": ["body", "items", 0, "fields"],
"msg": "argilla_server.api.schemas.v1.chat.ChatFieldValue() argument after ** must be a mapping, not str",
"type": "type_error",
"msg": "Value error, Error parsing chat field 'text-field': "
"argilla_server.api.schemas.v1.chat.ChatFieldValue() "
"argument after ** must be a mapping, not str",
"type": "value_error",
}
]
},
Expand Down Expand Up @@ -871,7 +873,7 @@ async def test_create_dataset_records_bulk_with_wrong_text_field_value(
},
)

assert response.status_code == 422
assert response.status_code == 422, response.json()
assert response.json() == expected_error
assert (await db.execute(select(func.count(Record.id)))).scalar_one() == 0

Expand Down

0 comments on commit 1c8f528

Please sign in to comment.