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

Allow attribute default/permitted values to be blank #6454

Merged
merged 2 commits into from
Jul 12, 2023
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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),
),
]
4 changes: 2 additions & 2 deletions cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Meta:

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:
Expand Down
4 changes: 0 additions & 4 deletions cvat/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5993,7 +5993,6 @@ components:
type: string
maxLength: 200
required:
- default_value
- input_type
- mutable
- name
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/python/sdk/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ def test_can_create_empty_project(self):
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)
Expand Down