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

Cyclic dependency error when using pick #2097

Closed
hoffmann-david opened this issue Aug 30, 2023 · 1 comment
Closed

Cyclic dependency error when using pick #2097

hoffmann-david opened this issue Aug 30, 2023 · 1 comment

Comments

@hoffmann-david
Copy link

hoffmann-david commented Aug 30, 2023

Describe the bug

Hi I am getting a cyclic dependency error when using pick()in combination with shape() in yup 1.2.0. The problem seems similar to #1969

To Reproduce

import { object, string } from 'yup';

const testObject = {
        a1: undefined,
        a2: 'over9000',
      };

      const a1 = string().when('a2', {
        is: undefined,
        then: (schema) => schema.required(),
      });
      const a2 = string().when('a1', {
        is: undefined,
        then: (schema) => schema.required(),
      });
      const schema = object({ a3: string().required(), a4: string().required() }).shape({ a1, a2 }, [
        ['a1', 'a2'],
      ]);

      const isValid = schema.pick(['a1', 'a2']).isValid(testObject);

Here is a very basic demo showing the resulting error: https://plnkr.co/edit/Nbdwma2bEbtSrxje

The resulting error is:
Error: Cyclic dependency, node was:"a2"

Expected behavior
The schema is able to validate properly for the picked fields.

Platform (please complete the following information):

  • Yup 1.2.0
@hoffmann-david
Copy link
Author

@jquense is there a known way to work around this problem?

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

No branches or pull requests

1 participant