fix(xo-server/collection/redis#{add,update}): cast to string before inserting in db

Fixes https://xcp-ng.org/forum/post/51933
Fixes #6359

Introduced by 36b94f745
This commit is contained in:
Julien Fontanet 2022-08-07 13:27:25 +02:00
parent c5d2726faa
commit d27b6bd49d

View File

@ -8,7 +8,6 @@ import ignoreErrors from 'promise-toolbox/ignoreErrors'
import isEmpty from 'lodash/isEmpty.js' import isEmpty from 'lodash/isEmpty.js'
import map from 'lodash/map.js' import map from 'lodash/map.js'
import omit from 'lodash/omit.js' import omit from 'lodash/omit.js'
import pickBy from 'lodash/pickBy.js'
import { v4 as generateUuid } from 'uuid' import { v4 as generateUuid } from 'uuid'
import Collection, { ModelAlreadyExists } from '../collection.mjs' import Collection, { ModelAlreadyExists } from '../collection.mjs'
@ -156,13 +155,16 @@ export default class Redis extends Collection {
} }
const key = `${prefix}:${id}` const key = `${prefix}:${id}`
const promises = [ const props = {}
redis.del(key), for (const name of Object.keys(model)) {
redis.hSet( if (name !== 'id') {
key, const value = model[name]
pickBy(model, (value, name) => value !== undefined && name !== 'id') if (value !== undefined) {
), props[name] = String(value)
] }
}
}
const promises = [redis.del(key), redis.hSet(key, props)]
// Update indexes. // Update indexes.
forEach(indexes, index => { forEach(indexes, index => {