Skip to content

Failure to render with "additionalProperties": True  #22

Description

@thclark
  • django-reactive version: 0.0.10
  • Django version: 3.1.8
  • Python version: 3.8.6
  • Operating System: ubuntu buster (python buster-slim container, running on OSX via docker),

Description

First, thanks for the library. It seems like early stages but this has the potential to become a n elegant solution to a lot of problems storing semi structured data in django+postgres.

I attempted to use a schema with the additionalProperties attribute set to True. This causes the form (in this case, for the 'tags' field) not to be rendered in django admin:

Screenshot 2021-04-30 at 12 36 28

Because JSON schema are able to use $REFs, it may not always be possible to force additionalProperties to false - and it's certainly not desirable, because it's good to be able to use the schema.

What I Did

I got the documented example to work and render the form in django admin.

Then I attempted to use the following schema:

Fails to render form

    tags = ReactJSONSchemaField(
        schema={
            "title": "Fails with additionalProperties True",
            "type": "object",
            "required": [
                "timezone",
            ],
            "properties": {
                "timezone": {
                    "type": "string",
                    "title": "Timezone",
                    "description": "Because met mast data files don't include timezone. Sigh!"
                },
            },
            "additionalProperties": True
        }
    )

The console output in chrome devtools shows:

**react-dom.js?Expires=1619868979&GoogleAccessId=stuff TypeError: Cannot convert undefined or null to object**
    at keys (<anonymous>)
    at utils.js:541
    at oe (utils.js:600)
    at B (utils.js:260)
    at r.value (Form.js:65)
    at new r (Form.js:35)
    at Yg (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:68)
    at rh (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:98)
    at zj (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:228)
    at Th (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:152)
Me @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:125
Ih.c.callback @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:138
Wg @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:67
oj @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:127
Aj @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:160
unstable_runWithPriority @ react.js?Expires=1619868979&GoogleAccessId=stuff:25
Da @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:60
ab @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:154
Te @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:146
Ja @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:224
md @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:173
(anonymous) @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:175
Rh @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:147
nd @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:175
I.render @ react-dom.js?Expires=1619868979&GoogleAccessId=stuff:238
djangoReactiveRenderForm @ django_reactive.js?Expires=1619868979&GoogleAccessId=stuff:76
(anonymous) @ (index):518

**react-dom.js?Expires=1619868979&GoogleAccessId=stuff:161 Uncaught TypeError: Cannot convert undefined or null to object**
    at keys (<anonymous>)
    at utils.js:541
    at oe (utils.js:600)
    at B (utils.js:260)
    at r.value (Form.js:65)
    at new r (Form.js:35)
    at Yg (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:68)
    at rh (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:98)
    at zj (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:228)
    at Th (react-dom.js?Expires=1619868979&GoogleAccessId=stuff:152)

(don't worry about google access id stuff, that's just the bucket I serve my static assets from)

By systematically comparing various missing / extra bits compared to the given example, I got the following schema to work:

Works:

    tags = ReactJSONSchemaField(
        schema={
            "title": "Works with additionalProperties False",
            "type": "object",
            "required": [
                "timezone",
            ],
            "properties": {
                "timezone": {
                    "type": "string",
                    "title": "Timezone",
                    "description": "Because met mast data files don't include timezone. Sigh!"
                },
            },
            "additionalProperties": False  # Also works if omitted, since False is default
        }
    )

Suggestion

Whilst it's certainly possible, it's a big undertaking to create a form which will allow on-the-fly creation of additionalProperties. So, maybe you don't actually want to do that. But even if you're not providing the scope for creating that additional data in django admin, I think the widget needs to not crash if the schema allows for it.

That way, the schema that you use for form generation can be made reusable.

Activity

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

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions