Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON default values are returned stringified by the API #15351

Closed
wc-davide opened this issue Sep 1, 2022 · 4 comments · Fixed by #19439
Closed

JSON default values are returned stringified by the API #15351

wc-davide opened this issue Sep 1, 2022 · 4 comments · Fixed by #19439

Comments

@wc-davide
Copy link

Describe the Bug

I created a Repeater field in directus with a default value (JSON Array) but once I save the field it converts the default value into a string.
When I try to create a new item in my collection it will then display a warning, which was added in this PR #12592
I'll also attach a screenshot of the database design of the field(MSSQL)

Creating the field with default value:
image

After saving this is how it looks:
image

MSSQL table design of the field:
image

To Reproduce

  1. Create a repeater field with a default value of (example):
[{"width":0,"size":25},{"width":600,"size":15},{"width":1200,"size":10}]
  1. Save
  2. Open the field again and see it has stored the default value as string
  3. Try to create a new item in the collection, it will display the warning/error

Errors Shown

When creating a new item in the collection:
image

What version of Directus are you using?

9.16.1

What version of Node.js are you using?

n/a

What database are you using?

MSSQL 2016

What browser are you using?

Brave

How are you deploying Directus?

k8s

@rijkvanzanten
Copy link
Member

@wc-davide Does this happen exclusively on repeater fields, or on any JSON type field with a default value?

@wc-davide
Copy link
Author

@wc-davide Does this happen exclusively on repeater fields, or on any JSON type field with a default value?

I tried creating a tags field:
image

Saving and reopening the field shows the default value as string on this one too:
image

But this time there's no error/warning when creating a new item, it just doesn't seems to work (no default values):
image

But it has data in "Edit Raw Value" (which I guess it doesn't show in the field because it can't parse it?):
image

@rijkvanzanten
Copy link
Member

But it has data in "Edit Raw Value" (which I guess it doesn't show in the field because it can't parse it?):

Yup! Same bug. In both cases, the default value isn't correctly cast back to JSON from the API 👍🏻

@rijkvanzanten rijkvanzanten changed the title Repeater default value is stored as string, making the default value not work JSON default values are returned stringified by the API Sep 2, 2022
@rijkvanzanten
Copy link
Member

Linear: ENG-197

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants