Skip to content

Commit

Permalink
fix: LEAP-245: make Number tag complain about missing to_name (#5408)
Browse files Browse the repository at this point in the history
* fix: LEAP-245: make Number tag complain about missing to_name (just TDD for now)

* add error message assertion

* unbreak closing view tag lol

* Fix validation config for Number

* Fix validation config for Number another try

* Fix tests assertion

---------

Co-authored-by: Jo Booth <jo.m.booth@gmail.com>
  • Loading branch information
Gondragos and jombooth committed Feb 1, 2024
1 parent a04f8cf commit dabf7b8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
35 changes: 33 additions & 2 deletions label_studio/core/utils/schema/label_config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@
}
}
},
"tag_with_name_and_toname": {
"type": "object",
"oneOf": [
{
"required": [
"@name",
"@toName"
]
}
],
"properties": {
"@name": {
"$ref": "#/definitions/@name"
},
"@toName": {
"$ref": "#/definitions/@toName"
},
"$": {
"$ref": "#/definitions/$"
}
}
},
"tag_with_value_required_name": {
"type": "object",
"oneOf": [
Expand Down Expand Up @@ -80,6 +102,13 @@
"items": {"$ref": "#/definitions/tag_with_value_required_name"}
}, {"$ref": "#/definitions/tag_with_value_required_name"}]
},
"tags_with_name_and_toname": {
"anyOf": [{"$ref": "#/definitions/tag_with_name_and_toname"},
{
"type": "array",
"items": {"$ref": "#/definitions/tag_with_name_and_toname"}
}]
},
"View": {
"type": "object",
"additionalProperties": true,
Expand All @@ -92,7 +121,8 @@
"Text": {"$ref": "#/definitions/tags_with_value_required_name"},
"HyperText": {"$ref": "#/definitions/tags_with_value_required_name"},
"View": {"$ref": "#/definitions/MaybeMultipleView"},
"TextArea": {"$ref": "#/definitions/MaybeMultipleTextAreas"}
"TextArea": {"$ref": "#/definitions/MaybeMultipleTextAreas"},
"Number": {"$ref": "#/definitions/tags_with_name_and_toname"}
}
},
"MaybeMultipleView": {
Expand Down Expand Up @@ -219,7 +249,8 @@
"Image": {"$ref": "#/definitions/tags_with_value_required_name"},
"Text": {"$ref": "#/definitions/tags_with_value_required_name"},
"HyperText": {"$ref": "#/definitions/tags_with_value_required_name"},
"TextArea": {"$ref": "#/definitions/MaybeMultipleTextAreas"}
"TextArea": {"$ref": "#/definitions/MaybeMultipleTextAreas"},
"Number": {"$ref": "#/definitions/tags_with_name_and_toname"}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions label_studio/tests/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ def test_config_validation_for_choices_workaround(business_client, project_id):
assert response.status_code == 200


@pytest.mark.django_db
def test_config_validation_for_missing_to_name_in_number_tag_fails(business_client, project_id):
"""
Validate Number tag with missing to_name fails (see LEAP-245)
"""
payload = {
'label_config': (
'<View>'
'<Text name="question" value="$question" granularity="word"/>'
'<Number name="number" to="question" required="true" />'
'</View>'
)
}
response = business_client.patch(
f'/api/projects/{project_id}',
data=json.dumps(payload),
content_type='application/json',
)
assert response.status_code == 400
response_data = response.json()
assert "'toName' is a required property" in response_data['validation_errors']['label_config'][0]


@pytest.mark.django_db
def test_parse_wrong_xml(business_client, project_id):
# Change label config to Repeater
Expand Down

0 comments on commit dabf7b8

Please sign in to comment.