mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 23:24:03 +00:00
Merge pull request #17636 from strapi/fix/json-types
Fix JSON parse on Postgres & Bulk Publish JSON validations
This commit is contained in:
commit
4a7f4c4926
@ -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 {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user