Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LEAP-245: make Number tag complain about missing to_name #5408

Merged
merged 7 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading