Merge pull request #17636 from strapi/fix/json-types

Fix JSON parse on Postgres & Bulk Publish JSON validations
This commit is contained in:
Fernando Chávez 2023-08-31 15:56:09 +02:00 committed by GitHub
commit 4a7f4c4926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -470,7 +470,11 @@ const SelectedEntriesModal = ({ onToggle }) => {
});
if (data.results) {
const schema = createYupSchema(contentType, { components }, { isDraft: false });
const schema = createYupSchema(
contentType,
{ components },
{ isDraft: false, isJSONTestDisabled: true }
);
const validationErrors = {};
const rows = data.results.map((entry) => {
try {

View File

@ -55,7 +55,12 @@ const getAttributes = (data) => get(data, ['attributes'], {});
const createYupSchema = (
model,
{ components },
options = { isCreatingEntry: true, isDraft: true, isFromComponent: false }
options = {
isCreatingEntry: true,
isDraft: true,
isFromComponent: false,
isJSONTestDisabled: false,
}
) => {
const attributes = getAttributes(model);
@ -215,6 +220,10 @@ const createYupSchemaAttribute = (type, validations, options) => {
schema = yup
.mixed(errorsTrads.json)
.test('isJSON', errorsTrads.json, (value) => {
if (options.isJSONTestDisabled) {
return true;
}
if (!value || !value.length) {
return true;
}

View File

@ -22,6 +22,12 @@ class PostgresDialect extends Dialect {
'text',
(v) => v
);
// Don't parse JSONB automatically
this.db.connection.client.driver.types.setTypeParser(
this.db.connection.client.driver.types.builtins.JSONB,
'text',
(v) => v
);
this.db.connection.client.driver.types.setTypeParser(
this.db.connection.client.driver.types.builtins.NUMERIC,
'text',