未验证 提交 1e18713a 编写于 作者: R Roman Donchenko 提交者: GitHub

Allow attribute default/permitted values to be blank (#6454)

This is de facto already allowed when CVAT is accessed via the UI/API,
even though the model/serializer configuration seem to prohibit it.
That's because validation for attribute properties is effectively
disabled on the server due to a bug. However, the SDK checks the schema,
and thus doesn't allow such values.

I think blank default values make sense (particularly for "text" type
attributes), so I updated the code to allow them.

Blank permitted values don't make quite as much sense, but I had to
allow them too, because the UI always submits the default value as the
first permitted value (even for freeform text attributes). This will let
us fix the broken validation on the server side (which I'm planning to
do soon) without removing the ability to set blank default attribute
values via the UI.

(FWIW, I don't think that the UI should add a `values` property when
serializing freeform text attributes at all, but it would take a more
substantial change to fix that, which I don't have time for right now.)
上级 a63f0f10
......@@ -19,7 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- TDB
### Fixed
- TDB
- \[SDK\] Ability to create attributes with blank default values
(<https://github.com/opencv/cvat/pull/6454>)
### Security
- TDB
......
# Generated by Django 4.2.1 on 2023-07-10 15:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("engine", "0072_alter_issue_updated_date"),
]
operations = [
migrations.AlterField(
model_name="attributespec",
name="default_value",
field=models.CharField(blank=True, max_length=128),
),
migrations.AlterField(
model_name="attributespec",
name="values",
field=models.CharField(blank=True, max_length=4096),
),
]
......@@ -881,8 +881,8 @@ class AttributeSpec(models.Model):
mutable = models.BooleanField()
input_type = models.CharField(max_length=16,
choices=AttributeType.choices())
default_value = models.CharField(max_length=128)
values = models.CharField(max_length=4096)
default_value = models.CharField(blank=True, max_length=128)
values = models.CharField(blank=True, max_length=4096)
class Meta:
default_permissions = ()
......
......@@ -214,7 +214,7 @@ class UserSerializer(serializers.ModelSerializer):
class AttributeSerializer(serializers.ModelSerializer):
values = serializers.ListField(allow_empty=True,
child=serializers.CharField(max_length=200),
child=serializers.CharField(allow_blank=True, max_length=200),
)
class Meta:
......
......@@ -5993,7 +5993,6 @@ components:
type: string
maxLength: 200
required:
- default_value
- input_type
- mutable
- name
......@@ -6011,16 +6010,13 @@ components:
$ref: '#/components/schemas/InputTypeEnum'
default_value:
type: string
minLength: 1
maxLength: 128
values:
type: array
items:
type: string
minLength: 1
maxLength: 200
required:
- default_value
- input_type
- mutable
- name
......
......@@ -115,6 +115,30 @@ class TestProjectUsecases:
assert project.id != 0
assert project.name == "test project"
def test_can_create_project_with_attribute_with_blank_default(self):
project = self.client.projects.create(
spec=models.ProjectWriteRequest(
name="test project",
labels=[
models.PatchedLabelRequest(
name="text",
attributes=[
models.AttributeRequest(
name="text",
mutable=True,
input_type=models.InputTypeEnum("text"),
values=[],
default_value="",
)
],
)
],
)
)
labels = project.get_labels()
assert labels[0].attributes[0].default_value == ""
def test_can_create_project_from_dataset(self, fxt_coco_dataset: Path):
pbar_out = io.StringIO()
pbar = make_pbar(file=pbar_out)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册