Skip to content

Commit f6cb4c4

Browse files
committed
Correct comments and logic on file size validator
1 parent 4ad369f commit f6cb4c4

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

core/validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, max_size):
3737
self.max_size = max_size
3838

3939
def __call__(self, value):
40-
if value.size > self.max_size:
40+
if value.size >= self.max_size:
4141
raise ValidationError(
4242
f"File too large. Size should not exceed {self.max_size / 1024 / 1024} MB." # noqa
4343
)
@@ -46,7 +46,7 @@ def __call__(self, value):
4646
# 1 MB max file size
4747
max_file_size_validator = MaxFileSizeValidator(max_size=1 * 1024 * 1024)
4848

49-
# 1 MB max file size
49+
# 5 MB max file size
5050
downscale_image_file_size_validator = MaxFileSizeValidator(max_size=5 * 1024 * 1024)
5151

5252
# 50 MB allowed for certain large files - to be used on staff-only fields

news/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_entry_model_image_file_size(tp):
102102
# This should not raise any errors
103103
entry.full_clean()
104104

105-
# This should fail (just over 1MB)
105+
# This should fail (just over 5MB)
106106
invalid_image = SimpleUploadedFile(
107107
"too_large.jpg", b"a" * (5 * 1024 * 1024 + 1), content_type="image/jpeg"
108108
)

0 commit comments

Comments
 (0)