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

Recursive definition no longer works in 5.4 #3560

Closed
3 of 4 tasks
Assumeru opened this issue Mar 31, 2023 · 3 comments · Fixed by #3571
Closed
3 of 4 tasks

Recursive definition no longer works in 5.4 #3560

Assumeru opened this issue Mar 31, 2023 · 3 comments · Fixed by #3571
Assignees
Labels

Comments

@Assumeru
Copy link

Assumeru commented Mar 31, 2023

Prerequisites

What theme are you using?

material-ui

Version

5.4.0

Current Behavior

A definition containing an array of which each array item is defined to be another instance of this definition leads to infinite recursion. Aside from the browser slowing down, a message gets logged in the console: could not merge subschemas in allOf: InternalError: too much recursion.

Expected Behavior

This same schema works fine in version 4.2, i.e. it doesn't recurse endlessly.

Steps To Reproduce

Paste this schema into https://rjsf-team.github.io/react-jsonschema-form/

Playground Link

{
  "definitions": {
    "@enum": {
      "type": "object",
      "properties": {
        "name": {
          "title": "Name",
          "type": "string",
          "minLength": 1
        },
        "_id": {
          "title": "Value",
          "type": "number"
        },
        "children": {
          "title": "Subvalues",
          "type": "array",
          "items": {
            "allOf": [
              {
                "$ref": "#/definitions/@enum"
              }
            ]
          }
        }
      }
    }
  },
  "type": "object",
  "properties": {
    "value": {
      "type": "array",
      "items": {
        "allOf": [
          {
            "$ref": "#/definitions/@enum"
          }
        ]
      },
      "minItems": 1
    }
  }
}

Environment

No response

Anything else?

I see a few other, older issues on the tracker that look similar, but these all appear to be from before version 5. #1160 appears to be about a nearly identical schema causing a similar issue along a different code path.

@Assumeru Assumeru added bug needs triage Initial label given, to be assigned correct labels and assigned labels Mar 31, 2023
@heath-freenome
Copy link
Member

@Assumeru Wow, yeah, we might have broken infinite recursion checking in the 5.x release. I will see how easy it is to fix it in the next week or so

@heath-freenome heath-freenome removed the needs triage Initial label given, to be assigned correct labels and assigned label Mar 31, 2023
@heath-freenome heath-freenome self-assigned this Mar 31, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Apr 3, 2023
Fixes rjsf-team#3560 by preventing infinite recursion on `$ref`s
- In `@rjsf/utils` added infinite recursion protection in the `toIdSchema()`, `toPathSchema()` and `getDefaultFormState()` functions
  - Added tests to verify that no infinite recursion due to `$ref`s happen for those three functions along with `retrieveSchema()`
  - Fixed the console.log() call for the `mergeAllOf` exceptions to log the whole error rather than the toString of it
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Apr 3, 2023
Fixes rjsf-team#3560 by preventing infinite recursion on `$ref`s
- In `@rjsf/utils` added infinite recursion protection in the `toIdSchema()`, `toPathSchema()` and `getDefaultFormState()` functions
  - Added tests to verify that no infinite recursion due to `$ref`s happen for those three functions along with `retrieveSchema()`
  - Fixed the console.log() call for the `mergeAllOf` exceptions to log the whole error rather than the toString of it
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Apr 3, 2023
Fixes rjsf-team#3560 by preventing infinite recursion on `$ref`s
- In `@rjsf/utils` added infinite recursion protection in the `toIdSchema()`, `toPathSchema()` and `getDefaultFormState()` functions
  - Added tests to verify that no infinite recursion due to `$ref`s happen for those three functions along with `retrieveSchema()`
  - Fixed the console.log() call for the `mergeAllOf` exceptions to log the whole error rather than the toString of it
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Apr 4, 2023
Fixes rjsf-team#3560 by preventing infinite recursion on `$ref`s
- In `@rjsf/utils` added infinite recursion protection in the `toIdSchema()`, `toPathSchema()` and `getDefaultFormState()` functions
  - Added tests to verify that no infinite recursion due to `$ref`s happen for those three functions along with `retrieveSchema()`
  - Fixed the console.log() call for the `mergeAllOf` exceptions to log the whole error rather than the toString of it
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit that referenced this issue Apr 4, 2023
* fix: Fixed infinite ref recursion in some utils functions
Fixes #3560 by preventing infinite recursion on `$ref`s
- In `@rjsf/utils` added infinite recursion protection in the `toIdSchema()`, `toPathSchema()` and `getDefaultFormState()` functions
  - Added tests to verify that no infinite recursion due to `$ref`s happen for those three functions along with `retrieveSchema()`
  - Fixed the console.log() call for the `mergeAllOf` exceptions to log the whole error rather than the toString of it
- Updated the `CHANGELOG.md` file accordingly

* - Removed the defaults on the internal functions and in the case of `toIdPrefixInternal()` reordered the props from the public API that are provided with defaults
  - This fixes test coverages

* - Fixed #2593 fully by also supporting data in `formData` in addition to data in `default` when dealing with `additionalProperties`
@estk
Copy link

estk commented Oct 11, 2023

The playground hangs for me with:

{
  "title": "A registration form",
  "description": "A simple form example.",
  "type": "object",
  "properties": {
    "child": {
      "$ref": "#"
    }
  }
}

@heath-freenome
Copy link
Member

@estk can you please write a new issue for this very extreme edge case so we can fix it?

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

Successfully merging a pull request may close this issue.

3 participants