Error when using advanced mode template

41 views
Skip to first unread message

mord reneth

unread,
Feb 20, 2017, 6:23:02 AM2/20/17
to OpenWISP
1. Add template
2. Enter name (test)
3. Select configutation menu->General
4. Click advanced/raw json mode.
5. Add "hosetname": "localhost"
6. Click save or preview.....error message in attached file is shown:



If adding via object properties/properties name.....works as expected.

Federico Capoano

unread,
Feb 20, 2017, 9:31:29 AM2/20/17
to OpenWISP
Hey, I can't replicate this bug.

Could you please paste the exact contents of the NetJSON data you find in "Advanced mode"?

Federico


On Monday, February 20, 2017 at 12:23:02 PM UTC+1, mord reneth wrote:
1. Add template
2. Enter name (test)
3. Select configutation menu->General
4. Click advanced/raw json mode.
5. Add "hosetname": "localhost"
6. Click save or preview.....error message in attached file is shown:

[cut]

mord reneth

unread,
Feb 20, 2017, 9:48:22 AM2/20/17
to OpenWISP
In my example, would be:

{
    "general": {
        "description": "",
        "maintainer": "",
        "ula_prefix": "",
        "timezone": "UTC"
        "hostname": "localhost"
    }
}


Thats it...

Federico Capoano

unread,
Feb 20, 2017, 12:59:24 PM2/20/17
to OpenWISP
Ok now I have replicated the bug.

There's a little mistake on your side but the system is failing to explain it properly.

There's a missing comma between "UTC" and "hostname". Try to paste this NetJSON into the advanced mode and it should work:

{
    "general": {
        "ula_prefix": "",
        "maintainer": "",
        "description": "",
        "timezone": "UTC",
        "hostname": "localhost"
    }
}

Regarding the failure of the system to explain the JSON syntax error properly, that's indeed a bug and I did not notice this before, thank you for reporting it! I opened an issue in the repository of the relevant module: [admin] JSON syntax errors not reported properly #30.

Federico

mord reneth

unread,
Feb 20, 2017, 11:34:07 PM2/20/17
to OpenWISP
of course! what a stupid mistake....

But, glad it brought up the bug.....


GASTON CHE

unread,
Mar 5, 2017, 5:06:37 PM3/5/17
to OpenWISP
This error also causes the advanced mode editor not to be able to load while trying to edit an existing configuration which was submitted with invalid json. Adding a graphical JSONEditor for advanced json editing while display json errors properly to the admin while editing configs, but this will not prevent the user from submitting the invalid json. I prevent that inorder to solve the issue https://github.com/openwisp/django-netjsonconfig/issues/30, there should be prevalidation of the json to make sure it is valid before it is even submitted, that way, invalid json never get stored.

GASTON CHE

unread,
Mar 5, 2017, 5:14:09 PM3/5/17
to OpenWISP
I am proposing a fix to this issue. I already submitted a PR for the addition of an advanced JSONEditor, which validates the validity of the JSON entered as well as validates the JSON against the schema provided for the configuration. Adding pre-validation to for the various pages that require advanced JSON editing, will not be difficult as the editor already validates the JSON.

Federico Capoano

unread,
Mar 6, 2017, 3:58:42 AM3/6/17
to OpenWISP
Great!

There's a django validation that forbids adding an invalid JSON into the database, but probably when the page is reloaded with the validation error shown, the editor doesn't load as you say, but haven't tried it. Could you send a link of your PR to JSONEditor?

Federico
Reply all
Reply to author
Forward
0 new messages