Skip to content

Commit

Permalink
Merge pull request #4041 from bjester/duration-constraint-madness
Browse files Browse the repository at this point in the history
Temporarily disable file duration check constraint
  • Loading branch information
bjester authored Apr 26, 2023
2 parents 15d1bb6 + 3cc1292 commit fbb9809
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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',
),
]
12 changes: 10 additions & 2 deletions contentcuration/contentcuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
]


Expand Down
2 changes: 2 additions & 0 deletions contentcuration/contentcuration/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions contentcuration/contentcuration/viewsets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pytest-pythonpath
pytest-timeout
pytest-watch
pre-commit==1.15.1
codecov
coverage
pytest-cov
nodeenv
Expand Down
4 changes: 0 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -220,7 +217,6 @@ pyzmq==23.1.0
requests==2.25.1
# via
# -c requirements.txt
# codecov
# coreapi
# locust
roundrobin==0.0.2
Expand Down

0 comments on commit fbb9809

Please sign in to comment.