Skip to content

Allow Cloud Validation "options" to be async #7140

Closed

Description

@dblythy

New Issue Checklist

Issue Description

As mentioned by @Cinezaster here, it is not possible to use async with a Parse.Cloud validator.

Steps to reproduce

Actual Outcome

Cloud function completes without running async validation

Expected Outcome

Validator should wait to run options function

Failing Test Case / Pull Request

  • 🤩 I submitted a PR with a fix and a test case.
  • 🧐 I submitted a PR with a failing test case.

Failing test:

it('set params options function async', async (done) => {
    Parse.Cloud.define(
      'hello',
      () => {
        fail('cloud function should not run.');
        return 'Hello world!';
      },
      {
        fields: {
          data: {
            type: Number,
            required: true,
            options: async val => {
              await new Promise((resolve, reject) => {
                setTimeout(resolve, 500);
              })
              return false;
            },
            error: 'Validation failed. Expected data to be between 1 and 5.',
          },
        },
      }
    );
    try {
    await Parse.Cloud.run('hello', { data: 7 })
    } catch (error) {
      expect(error.code).toEqual(Parse.Error.VALIDATION_ERROR);
      expect(error.message).toEqual('Validation failed. Expected data to be between 1 and 5.');
    }
    done();
  });

Environment

Server

  • Parse Server version: 4.5.0
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): FILL_THIS_OUT

Database

  • System (MongoDB or Postgres): FILL_THIS_OUT
  • Database version: FILL_THIS_OUT
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): FILL_THIS_OUT

Logs

Activity

  1. mtrezza commented on Jan 22, 2021

    @mtrezza
    Member

    Thanks for opening this issue.

    It sounds reasonable to allow async validation. I understand from your comment that you are already working on a PR. Just to let others know that this is in the works.

  2. dblythy commented on Jan 22, 2021

    @dblythy
    MemberAuthor

    Yeah, thank you Manuel. Sorry I have been a bit busy lately and haven't been able to close out my other pending PRs. I'll try to get to that.

  3. added
    type:featureNew feature or improvement of existing feature
    and removed on Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions