diff --git a/contentcuration/contentcuration/migrations/0142_remove_file_file_media_duration_int.py b/contentcuration/contentcuration/migrations/0142_remove_file_file_media_duration_int.py new file mode 100644 index 0000000000..e497fbd398 --- /dev/null +++ b/contentcuration/contentcuration/migrations/0142_remove_file_file_media_duration_int.py @@ -0,0 +1,16 @@ +# Generated by Django 3.2.18 on 2023-04-26 18:55 +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('contentcuration', '0141_add_task_signature'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='file', + name='file_media_duration_int', + ), + ] diff --git a/contentcuration/contentcuration/models.py b/contentcuration/contentcuration/models.py index f9f5852f31..8bf951e5a3 100644 --- a/contentcuration/contentcuration/models.py +++ b/contentcuration/contentcuration/models.py @@ -2076,7 +2076,13 @@ class StagedFile(models.Model): FILE_DISTINCT_INDEX_NAME = "file_checksum_file_size_idx" FILE_MODIFIED_DESC_INDEX_NAME = "file_modified_desc_idx" FILE_DURATION_CONSTRAINT = "file_media_duration_int" -MEDIA_PRESETS = [format_presets.AUDIO, format_presets.VIDEO_HIGH_RES, format_presets.VIDEO_LOW_RES] +MEDIA_PRESETS = [ + format_presets.AUDIO, + format_presets.AUDIO_DEPENDENCY, + format_presets.VIDEO_HIGH_RES, + format_presets.VIDEO_LOW_RES, + format_presets.VIDEO_DEPENDENCY, +] class File(models.Model): @@ -2213,7 +2219,9 @@ class Meta: models.Index(fields=["-modified"], name=FILE_MODIFIED_DESC_INDEX_NAME), ] constraints = [ - models.CheckConstraint(check=(Q(preset__in=MEDIA_PRESETS, duration__gt=0) | Q(duration__isnull=True)), name=FILE_DURATION_CONSTRAINT) + # Commented out to temporarily remove the constraint until we can re-run `set_file_duration` + # on all media files with the dependency preset in the database. + # models.CheckConstraint(check=(Q(preset__in=MEDIA_PRESETS, duration__gt=0) | Q(duration__isnull=True)), name=FILE_DURATION_CONSTRAINT) ] diff --git a/contentcuration/contentcuration/tests/test_models.py b/contentcuration/contentcuration/tests/test_models.py index 97d3359ce7..b8dfada4f8 100644 --- a/contentcuration/contentcuration/tests/test_models.py +++ b/contentcuration/contentcuration/tests/test_models.py @@ -651,6 +651,7 @@ def test_duration_check_constraint__acceptable(self): duration=1123123, ) + @pytest.mark.skip(reason="Temporarily removed constraint") def test_duration_check_constraint__negative(self): channel = testdata.channel() with self.assertRaises(IntegrityError, msg=FILE_DURATION_CONSTRAINT): @@ -660,6 +661,7 @@ def test_duration_check_constraint__negative(self): duration=-10, ) + @pytest.mark.skip(reason="Temporarily removed constraint") def test_duration_check_constraint__not_media(self): channel = testdata.channel() with self.assertRaises(IntegrityError, msg=FILE_DURATION_CONSTRAINT): diff --git a/contentcuration/contentcuration/viewsets/file.py b/contentcuration/contentcuration/viewsets/file.py index 132bfe0769..922d6f276d 100644 --- a/contentcuration/contentcuration/viewsets/file.py +++ b/contentcuration/contentcuration/viewsets/file.py @@ -148,6 +148,8 @@ def upload_url(self, request): if not isinstance(duration, (int, float)): return HttpResponseBadRequest(reason="File duration must be a number") duration = math.floor(duration) + if duration <= 0: + return HttpResponseBadRequest(reason="File duration is equal to or less than 0") try: request.user.check_space(float(size), checksum) diff --git a/requirements-dev.in b/requirements-dev.in index 6c3b1033f8..b2bfb0931c 100644 --- a/requirements-dev.in +++ b/requirements-dev.in @@ -14,7 +14,6 @@ pytest-pythonpath pytest-timeout pytest-watch pre-commit==1.15.1 -codecov coverage pytest-cov nodeenv diff --git a/requirements-dev.txt b/requirements-dev.txt index 383ee77801..07d875e98f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -35,8 +35,6 @@ click==8.1.3 # -c requirements.txt # flask # pip-tools -codecov==2.1.12 - # via -r requirements-dev.in colorama==0.4.4 # via pytest-watch configargparse==1.5.3 @@ -50,7 +48,6 @@ coreschema==0.0.4 coverage[toml]==6.2 # via # -r requirements-dev.in - # codecov # pytest-cov customizable-django-profiler @ git+https://github.com/someshchaturvedi/customizable-django-profiler.git # via -r requirements-dev.in @@ -220,7 +217,6 @@ pyzmq==23.1.0 requests==2.25.1 # via # -c requirements.txt - # codecov # coreapi # locust roundrobin==0.0.2