From a1c425f73334fa0851c25e5fdcc48e565783ad22 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Thu, 26 Oct 2023 11:42:09 +0800 Subject: [PATCH] fix: error when post create action with emtpy value (#2916) * fix: error when post create action with emtpy value * chore: sanitize --- .../core/actions/src/__tests__/create-action.test.ts | 9 +++++++++ packages/core/database/src/update-guard.ts | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/actions/src/__tests__/create-action.test.ts b/packages/core/actions/src/__tests__/create-action.test.ts index 43e8b7491..6b50bf696 100644 --- a/packages/core/actions/src/__tests__/create-action.test.ts +++ b/packages/core/actions/src/__tests__/create-action.test.ts @@ -108,4 +108,13 @@ describe('create action', () => { expect(await tag.hasPost(p1)).toBeTruthy(); expect(tag.get('name')).toEqual('hello'); }); + + test('create with empty values', async () => { + const response = await app.agent().resource('posts').create({}); + expect(response.statusCode).toEqual(200); + const p1 = await Post.repository.findOne(); + + const response2 = await app.agent().resource('posts.comments', p1.get('id')).create({}); + expect(response2.statusCode).toEqual(200); + }); }); diff --git a/packages/core/database/src/update-guard.ts b/packages/core/database/src/update-guard.ts index 122c93b97..a8603758e 100644 --- a/packages/core/database/src/update-guard.ts +++ b/packages/core/database/src/update-guard.ts @@ -2,7 +2,6 @@ import lodash from 'lodash'; import { ModelStatic } from 'sequelize'; import { Model } from './model'; import { AssociationKeysToBeUpdate, BlackList, WhiteList } from './repository'; -import { isPlainObject } from '@nocobase/utils/src'; type UpdateValueItem = string | number | UpdateValues; @@ -100,6 +99,10 @@ export class UpdateGuard { * @param values */ sanitize(values: UpdateValues) { + if (values === null || values === undefined) { + return values; + } + values = lodash.clone(values); if (!this.model) {