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

[4.x]: Validation of assets on upload no longer works as expected #11156

Closed
aelvan opened this issue May 8, 2022 · 3 comments · Fixed by #11177
Closed

[4.x]: Validation of assets on upload no longer works as expected #11156

aelvan opened this issue May 8, 2022 · 3 comments · Fixed by #11177
Assignees

Comments

@aelvan
Copy link

aelvan commented May 8, 2022

What happened?

Description

Adding validation errors to assets on upload no longer works as expected (ie the way it used to do in Craft 3.x).

Steps to reproduce

  1. Add the following event handler to a module or a plugin:
Event::on(
    Asset::class,
    Model::EVENT_BEFORE_VALIDATE,
    static function (ModelEvent $event) {
        /** @var Asset $asset */
        $asset = $event->sender;
        $asset->addError('title', 'This asset does not validate!');
    }
);
  1. Upload an asset

Expected behavior

In Craft 3.x, this resulted in an alert popping up saying "Upload failed. The error message was: “This asset does not validate!”", and when clicking "Ok" the upload was aborted and you returned to the assets element index.

Actual behavior

In Craft 4.x, there is no error message, the status bar just stays on screen and nothing happens.

Two things I noticed:

  • In Craft 3, the response is a http 200, while in Craft 4 it's a 400
  • In Craft 3, a json object with one key, error, is returned, while in Craft 4 the key is called message.

Craft CMS version

4.0.1

PHP version

8.1.5

Operating system and version

macOS 11.2

Database type and version

MySQL 5.7.38

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-32)

Installed plugins and versions

@timkelty timkelty self-assigned this May 9, 2022
timkelty added a commit that referenced this issue May 10, 2022
@timkelty
Copy link
Contributor

timkelty commented May 10, 2022

@aelvan Thanks for the report! Returning a 400 with message is correct in Craft 4, it just wasn't being handled properly.

This is fixed on #11177 if you want to test with dev-fix-asset-upload as 4.0.2.

@brandonkelly
Copy link
Member

That fix is merged into develop and release/4.0.2 now.

@brandonkelly
Copy link
Member

Craft 4.0.2 is out now with the fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants