Broken UUID broke whole section on admin side
zerc opened this issue · 0 comments
zerc commented
If we get broken UUID which don't pass UUID_WITH_EFFECTS_REGEX
check - then we got 500 error in production because:
class FileField(six.with_metaclass(models.SubfieldBase, models.Field)):
"""Django model field that stores uploaded file as Uploadcare CDN url.
"""
def to_python(self, value):
if value is None or value == '':
return value
if isinstance(value, File):
return value
if not isinstance(value, six.string_types):
raise ValidationError(
'Invalid value for a field: string was expected'
)
try:
return File(value)
except InvalidRequestError as exc:
raise ValidationError(
'Invalid value for a field: {exc}'.format(exc=exc)
)
Raised ValidationError
from to_python
method bring us 500 error.
Simple case (used test_project
):
from gallery.models import *
photo = Photo.objects.all()[0]
photo.arbitrary_file.uuid += 'ad' # Will be nice if we raise exception in this point
photo.save()
And now if we try to open just section /admin/gallery/photo/
- we catch error page.
I think we need change File.uuid
to descriptor. Then we get full control over changing it value:
photo.arbitrary_file.uuid += 'ad' # exception. We can't change it on invalid value