Verify custom field string syntax

arielma2304
arielma2304 Registered Posts: 47 ✭✭✭✭

Hi

I've read this article:

custom-fields

And I was wondering how can I verify the input of String type? I want it to get only version (as example '3.2.1'), and if not, it should throw exception

I guess it should be done thought the python-lib folder, and using the `from packaging import version`

Tagged:

Answers

  • StanG
    StanG Dataiker, Registered Posts: 52 Dataiker

    Hi,

    The verification of the content of plugin component parameters can be done in the python backend.
    For example, in a custom recipe of a plugin, you can check the parameter value after loading the recipe config (with dataiku.customrecipe.get_recipe_config) and raise errors if needed.

  • arielma2304
    arielma2304 Registered Posts: 47 ✭✭✭✭

    Can you give me example based on my case? assuming this is my JSON:

    {
    "meta": {
    "label": "Version",

    "description": "my description",

    "icon": "icon-puzzle-piece"
    },
    "customFields": [
    {
    "applyToObjects": {
    "mode": "ALL"
    },
    "field": {
    "name": "Version",
    "label": "Last Bundle Version",
    "type": "STRING",
    "defaultValue": "1.0.0"
    }
    }
    ]
    }

    now, How can I validate that the input for the `Last Bundle Version` field is in the correct Version Syntax using python packaging? Where I'm adding the code that once someone trying hardcoded to change the value thought the UI (for example to "Test") it throws exception?

  • StanG
    StanG Dataiker, Registered Posts: 52 Dataiker

    Hi,
    Sorry I was referring to plugin parameters instead of custom fields.
    For the moment you can't do string validation in the UI and there is no python backend with custom fields components.
    You could only check the string when using its value in a future code.

  • arielma2304
    arielma2304 Registered Posts: 47 ✭✭✭✭

    I think you should consider also adding type of Version in the supported type.

    BTW, if its not supported, why the python-lib folder is there? what it is used for?

Setup Info
    Tags
      Help me…