WatermelonDB icon indicating copy to clipboard operation
WatermelonDB copied to clipboard

TypeError: sanitizer is not a function

Open ndrkltsk opened this issue 7 years ago • 7 comments

While I try to insert json data, I get:

TypeError: sanitizer is not a function

The column type is string in schema, and the decorators are setup like in docs: https://github.com/Nozbe/WatermelonDB/blob/master/docs/Advanced/AdvancedFields.md#json

ndrkltsk avatar Feb 22 '19 10:02 ndrkltsk

@ndrkltsk Can you show definitions of the field and the sanitize function?

rkrajewski avatar Feb 22 '19 14:02 rkrajewski

Hello, I have the same error Model

import {field, json} from '@nozbe/watermelondb/decorators'

export default class Novel extends Model {
    static table = tableName;
    //some fields
    @json('genres', genresSanitizer) genres;
}

const genresSanitizer = input => {
    return input;
}

Schema

import {tableSchema} from '@nozbe/watermelondb'

export default tableSchema({
    name,
    columns: [
        //...
        {name: 'genres', type: 'string', isOptional: true},
    ]
})

my input on genres field is an array:

["Tiên Hiệp"]

my error:

TypeError: sanitizer is not a function
    at Novel.set [as genres] ...

package.json

     "@nozbe/watermelondb": "^0.10.1",
    "react": "16.6.3",
    "react-native": "^0.58.4",
    "es6-symbol": "^3.1.1",

vdthieu avatar Mar 07 '19 11:03 vdthieu

What's your babel config?

radex avatar Mar 07 '19 21:03 radex

@radex .babelrc

{
  "presets": [
    "module:metro-react-native-babel-preset"
  ],
  "plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ]
}

package.json

    "@babel/plugin-proposal-decorators": "^7.3.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "24.1.0",
    "babel-preset-react-native": "^5",
    "@babel/runtime": "^7.2.0",
    "babel-plugin-idx": "^2.2.0",
    "babel-plugin-transform-remove-console": "^6.9.0",

vdthieu avatar Mar 08 '19 03:03 vdthieu

@vdthieu Were you able to resolve this?

pramodgobburi3 avatar Jun 23 '20 23:06 pramodgobburi3

It was a hoisting issue on my side, moving the sanitizer const above the export default worked for me

mhyassin avatar Sep 19 '23 13:09 mhyassin

The problem was happening with JSON fields on model. I switched them to TEXT and the sanitizer error gone. "@json("geo_json") geo_json;" TO "@text("geo_json") geo_json;"

rodolforamos avatar Oct 08 '24 20:10 rodolforamos