Git Product home page Git Product logo

Comments (12)

bhch avatar bhch commented on September 23, 2024 2

default=dict is what's causing the problem.

The widget is receiving {} as the default data which doesn't match any subschemas listed under oneOf.

To fix it, you should:

  • either stop providing a default value. The widget will automatically create appropriate empty data, so I don't think you should worry about it.
  • or if you must, then the default value must match at least one of the subschemas, e.g.: default={"and": []}.

Anyway, I'll mark this issue as a bug because the widget should handle this type of cases more gracefully and should produce helpful error messages.

from django-jsonform.

bhch avatar bhch commented on September 23, 2024 1

@sgocg I am able to reproduce the error now. It's a separate issue altogether. Will be tracked in #131.

from django-jsonform.

bhch avatar bhch commented on September 23, 2024

Which version are you on? Check using:

$ python -c "import django_jsonform; print(django_jsonform.__version__)"

from django-jsonform.

abhishek-compro avatar abhishek-compro commented on September 23, 2024

Which version are you on?

2.17.0

from django-jsonform.

bhch avatar bhch commented on September 23, 2024

So I did some tests. Seems to work as expected.

Here's an animated GIF:

animated gif


What issues are you getting?

from django-jsonform.

abhishek-compro avatar abhishek-compro commented on September 23, 2024

I was getting the following error:

TypeError: t is undefined
    Re http://localhost:8000/static/django_jsonform/react-json-form.js:1
    g http://localhost:8000/static/django_jsonform/react-json-form.js:1
    _e http://localhost:8000/static/django_jsonform/react-json-form.js:1
    render http://localhost:8000/static/django_jsonform/react-json-form.js:1
    React 13
    render http://localhost:8000/static/django_jsonform/react-json-form.js:1
    initJSONForm http://localhost:8000/static/django_jsonform/index.js:62
    initializeAllForNode http://localhost:8000/static/django_jsonform/index.js:100
    init http://localhost:8000/static/django_jsonform/index.js:105
    <anonymous> http://localhost:8000/static/django_jsonform/index.js:145
    EventListener.handleEvent* http://localhost:8000/static/django_jsonform/index.js:144
    <anonymous> http://localhost:8000/static/django_jsonform/index.js:149
react-dom.production.min.js:141:274

What should I do?

Edit: Got this in Firefox

from django-jsonform.

bhch avatar bhch commented on September 23, 2024

Try disabling your browser cache.

If this is a production environment, you must also run the collectstatic command to replace old static files with new ones.

from django-jsonform.

abhishek-compro avatar abhishek-compro commented on September 23, 2024

Got this in chrome:

react-dom.production.min.js:141 TypeError: Cannot read properties of undefined (reading 'length')
    at Re (react-json-form.js:1:52698)
    at g (react-json-form.js:1:56760)
    at _e (react-json-form.js:1:57098)
    at a.render (react-json-form.js:1:59517)
    at Te (react-dom.production.min.js:119:308)
    at Ch (react-dom.production.min.js:119:105)
    at Pj (react-dom.production.min.js:233:139)
    at di (react-dom.production.min.js:168:305)
    at Nj (react-dom.production.min.js:168:236)
    at sc (react-dom.production.min.js:168:96)

Try disabling your browser cache.

I did clear the browser cache and reinstalled all the packages in a fresh project and got the same error. How do I disable the cache though?

Its development environment.

To be more precise I am using the following model:

class UserFilter(models.Model):
    filters = JSONField(
        schema={
            "$defs": {
                "and": {
                    "type": "object",
                    "properties": {
                        "and": {
                            "type": "array",
                            "items": {
                                "oneOf": [
                                    {"$ref": "#/$defs/and", "title": "and"},
                                    {"$ref": "#/$defs/or", "title": "or"},
                                ]
                            },
                        }
                    },
                },
                "or": {
                    "type": "object",
                    "properties": {
                        "or": {
                            "type": "array",
                            "items": {
                                "oneOf": [
                                    {"$ref": "#/$defs/and", "title": "and"},
                                    {"$ref": "#/$defs/or", "title": "or"},
                                ]
                            },
                        }
                    },
                },
            },
            "oneOf": [
                {"$ref": "#/$defs/and", "title": "and"},
                {"$ref": "#/$defs/or", "title": "or"},
            ],
        },
        default=dict,
    )
    name = models.CharField(max_length=512, unique=True)

What are you using?

from django-jsonform.

abhishek-compro avatar abhishek-compro commented on September 23, 2024

That worked. Thanks!!

from django-jsonform.

sgocg avatar sgocg commented on September 23, 2024

I'm running into a similar issue (at least the stacktrace is the same as mentioned in #101 (comment)) when adding a new array field to the schema.

A minimal version of my schema looks as follows:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
  }
}

If I update the schema to the following value:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "tags": {
      "type": "array",
      "items": {"type": "string"}
    }
  }
}

... for existing values in the database (eg. {"name": "Example"}) the admin widget doesn't render and shows this message instead: (!) TypeError: Cannot read properties of undefined (reading 'length').

Interestingly, this only happens if the type of tags is array. If set the type to something else (eg. string), the admin widget renders fine and it's also possible to update the tags value using the widget. I tried providing a default value in the schema but unfortunately it didn't help.

from django-jsonform.

bhch avatar bhch commented on September 23, 2024

@sgocg Hi, I just tested the scenario you mentioned. It's working completely fine for me. I tested with the latest version (2.21.0).

Which version are you using?

from django-jsonform.

sgocg avatar sgocg commented on September 23, 2024

Thanks for testing it out. And apologies that the previous schema wasn't fully representative. I tried pasting a (much too) simplified version of the schema as my original schema is quite large.

In any case, I was able to simplify it differently now. Here's the original schema:

{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "title": "Example",
      "oneOf": [
        {
          "title": "Table",
          "properties": {
            "type": {
              "type": "string",
              "default": "table",
              "widget": "hidden"
            },
            "columns": {
              "title": "Columns",
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "title": "Header"
                  },
                  "type": {
                    "type": "string",
                    "title": "Type",
                    "choices": [
                      "string",
                      "number",
                      "integer",
                      "boolean"
                    ],
                    "default": "string",
                    "required": true
                  },
                  "default": {
                    "type": "array",
                    "title": "Prepopulate rows (EN)",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}

If I update the schema to this:

{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "title": "Example",
      "oneOf": [
        {
          "title": "Table",
          "properties": {
            "type": {
              "type": "string",
              "default": "table",
              "widget": "hidden"
            },
            "columns": {
              "title": "Columns",
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "title": "Header"
                  },
                  "type": {
                    "type": "string",
                    "title": "Type",
                    "choices": [
                      "string",
                      "number",
                      "integer",
                      "boolean"
                    ],
                    "default": "string",
                    "required": true
                  },
                  "default": {
                    "type": "array",
                    "title": "Prepopulate rows (EN)",
                    "items": {
                      "type": "string"
                    }
                  },
                  "default_de": {
                    "type": "array",
                    "title": "Prepopulate rows (DE)",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}

... i.e. add the default_de property, the admin widget doesn't render with the following message:
Screenshot 2023-11-28 at 10 02 20 AM

In the database I'm using the following value:

{
  "data": {
    "type": "table",
    "columns": [
      {
        "type": "string",
        "title": "Column 1",
        "default": [
          "first",
          "second",
          "third"
        ]
      },
      {
        "type": "number",
        "title": "Column 2",
        "default": []
      },
      {
        "type": "string",
        "title": "Column 3",
        "default": []
      }
    ]
  }
}

I was using 2.17.0 earlier but upgraded to 2.21.0 but the problem still persists.

from django-jsonform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.