Skip to content

Conversation

@petersg83
Copy link
Contributor

@petersg83 petersg83 commented Feb 8, 2023

What does it do?

Fix #15496

Why is it needed?

On Postgres, when the JSON value was a simple string, the value was parsed twice instead of once.

How to test it?

  1. In the getStarted example, add a JSON field named "myjson"
  2. Use this following bootstrap function
async bootstrap({ strapi }) {
    await strapi.entityService.create('api::country.country', { data: { name: 'Imagine the people', myjson: "coucou" } });
  },
  1. See no error

Related issue(s)/PR(s)

@petersg83 petersg83 added source: core:database Source is core/database package pr: fix This PR is fixing a bug labels Feb 8, 2023
@codecov
Copy link

codecov bot commented Feb 8, 2023

Codecov Report

Base: 59.25% // Head: 59.25% // No change to project coverage 👍

Coverage data is based on head (52bcdad) compared to base (17a7845).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15752   +/-   ##
=======================================
  Coverage   59.25%   59.25%           
=======================================
  Files        1547     1547           
  Lines       39104    39104           
  Branches     7507     7507           
=======================================
  Hits        23172    23172           
  Misses      13638    13638           
  Partials     2294     2294           
Flag Coverage Δ
back 47.32% <ø> (ø)
front 67.21% <ø> (ø)
unit_back 47.32% <ø> (ø)
unit_front 67.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@cpaczek
Copy link
Collaborator

cpaczek commented Feb 8, 2023

Not sure this fixes much? Setting the type parser on the pg driver layer as it still is going to still try and parse it here: https://github.com/strapi/strapi/blob/main/packages/core/database/lib/fields/json.js

The issue is that the field is being parsed via Strapi above so I would assume this would have the same issue but I haven't tested this branch.

@cpaczek
Copy link
Collaborator

cpaczek commented Feb 8, 2023

Oh is the issue that it's being parsed twice? if so then yes this would fix it.

@cpaczek
Copy link
Collaborator

cpaczek commented Feb 13, 2023

Just tested this and everything seems to be working, it will even "fix" databases that were broken before. Could we get this merged soon people are mentioning this in the discord and it has the possibility to brick admin panels for existing users.

Copy link
Contributor

@Marc-Roig Marc-Roig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 Very good catch ! 🐛

Everything seems to be working, I don't get any error either :)

@strapi-bot
Copy link

This pull request has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/no-validation-if-you-post-a-content-through-api/25747/4

@petersg83 petersg83 added this to the 4.6.2 milestone Feb 13, 2023
@petersg83 petersg83 merged commit 6a0e1ba into main Feb 13, 2023
@petersg83 petersg83 deleted the fix/postgres-json-string branch February 13, 2023 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: fix This PR is fixing a bug source: core:database Source is core/database package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad JSON data breaks API and admin dashboard

5 participants