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
Default value for boolean fields set as String #14356
Comments
Setting the default value to 0 manually in the sqlite database schema fixes everything. so i would argue that the default value set by directus is wrong |
Initially I wasn't able to reproduce this: chrome_Bem4g3y8T4.mp4But after doing further testings, it seems like it exclusively happens AFTER updating the default value back to chrome_J9prCn41KJ.mp4 |
@azrikahar Feels like it could be similar to the issue addressed here knex/knex-schema-inspector#117. When updating a column to nullable in most DB vendors, it tends to return string null as the default. We should verify boolean cases for all DB vendors. |
That's a good point. I haven't dig into this too much, but would this portion of the code already be the verification you're mentioning? 🤔 (which makes this even more odd on what regression could be happening, or was this never caught in the first place) directus/api/src/utils/get-default-value.ts Lines 32 to 42 in 9e387fe
|
@azrikahar I didn't realize there was already explicit boolean handling in that helper, but yes, that should handle this case. It could be that the helper doesn't account for whitespace? I know it was possible for nullable values to be returned as 'null ' from the schema query. Either way, I personally don't like that this is handled in a helper function in Directus. It's my opinion that |
Looked into this a bit more, and I'm not sure if this is accurate, but here are my thoughts: The API does seem to correctly pass directus/api/src/services/fields.ts Lines 586 to 602 in a803331
But it seems like the which may explain why this default value bug only happens when updating it, not when creating it. Not sure if the formatDefault here was not ran somewhere before alterColumn(): https://github.com/knex/knex/blob/2dadde4214d9ee333adccfa517089647e94d23be/lib/formatter/formatterUtils.js#L21-L36, or it's not formatting properly. Would love to hear from @nickrum since I'm still not entirely sure here. |
Thanks for taking a look @azrikahar. Changing that line from formatDefault(col.modified['defaultTo'][0], type, this.client) to formatDefault(col.modified['defaultTo'][0], col.type, this.client) fixed the issue for me. |
This will be fixed by knex/knex#5319. |
Linear: ENG-231 |
Describe the Bug
i have a boolean input field where i set the default value to false
then i create a new entry without the boolean input (which should be set to the default value false)
However the field is created as a string "false" not false
To Reproduce
Errors Shown
No response
What version of Directus are you using?
9.14.1
What version of Node.js are you using?
16
What database are you using?
SQLITE
What browser are you using?
FF
How are you deploying Directus?
local
The text was updated successfully, but these errors were encountered: