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

Not allowed extension not showing in the error message. #11802

Open
Hlamallama opened this issue Mar 26, 2024 · 1 comment · May be fixed by #11879
Open

Not allowed extension not showing in the error message. #11802

Hlamallama opened this issue Mar 26, 2024 · 1 comment · May be fixed by #11879
Labels
status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug

Comments

@Hlamallama
Copy link

Issue Summary

Not allowed extension showing as blank when using the WAGTAILDOCS_EXTENSIONS setting.

Steps to Reproduce

  1. Start a new project with wagtail start myproject
  2. Add WAGTAILDOCS_EXTENSIONS = ["doc", "pdf"]
  3. Log onto Wagtail, navigate to Documents on the side menu
  4. Add a new document with txt extension.
  5. Error thrown File extension “” is not allowed. Allowed extensions are: doc, docx, pdf. Instead of File extension “txt” is not allowed. Allowed extensions are: doc, docx, pdf

image (1)

Technical details

  • Python version: 3.11.5
  • Django version: 5.0.3
  • Wagtail version: 6.0
  • Browser version: Chrome 122 and Firefox 123

Working on this

Anyone can contribute to this. View our contributing guidelines, add a comment to the issue once you’re ready to start.

@Hlamallama Hlamallama added status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug labels Mar 26, 2024
@rd3m
Copy link

rd3m commented Mar 28, 2024

It looks like there's a deeper issue here, the user shouldn't be presented with a successful upload message and then shown an error when they hit Update because the upload has actually failed already.

For example, with: WAGTAILDOCS_EXTENSIONS = ["doc", "pdf"]:
image

The .webp file hasn't actually successfully uploaded, if we navigate to the list of Documents, it's not there. Hitting Update then shows the validation error:
image

I think this is happening because the FileExtensionValidator adds the error to __all__ but when checking if the form is valid, we check the "file" key. If we add the error to the "file" key then the validation error is caught before the file is uploaded:
image

The below is a potential solution to get the above result but I'm not sure it's the best solution!
In the model clean method:

if allowed_extensions:
    validate = FileExtensionValidator(allowed_extensions)
    try:
        validate(self.file)
    except ValidationError as e:
        raise ValidationError(
            { "file": e.messages[0] }
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants