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
Toggle interface doesn't work properly with MySQL's tinyint(1) #8480
Comments
Hello, |
Hi @RemiMatrod , Could you try what happens if you make the tinyint column |
I think I found something: |
Ah that makes total sense actually, and works as expected. That special flag instructs the API to treat the column as a boolean. When you setup the field from Directus, it'll set that flag, which is why I wasn't able to repro it before (as I created the field in Directus, and then change the type afterwards). The main question becomes how and if to fix that 🤔 An unsigned tinyint(1) is technically any number from 0-255, so we wouldn't want to require that to be a boolean. I think the only way forward here is to treat this as a new feature, where the app will ask you what type to use for an existing column once you select it in the data model settings. In this case, it's ambiguous whether to use an integer (as per the type "strictly") or a boolean (which is arguably a more common use for tinyint(1)). Tricky stuff! |
I would think a column of type tinyint(1) should be treated as being a tiny int, because that's what it is. I don't see the point of using a special flag, as we know the column datatype and interface type, that should be enough to map the value from interface to column datatype and vice versa. |
Yeah, it's the API that does the data casting based on the value 👍🏻 Instead of having the app convert 1 to true all over the place, the API handles this to standardize the output for columns that are intended to be used as a boolean. (Similarly, CSV values use JSON Arrays for IO, Dates are done in ISO8601, etc) |
That's exactly how I would think it should work. But since the API knows which interface is used and what the underlying datatype is, casting the value from tinyint to bool and vv shouldn't be a problem for the API, right? |
Right, but we can't use it exclusively on the interface, as interfaces can be user-created, so we can't keep a list of the type based on the interface. Also, you might not even have an interface configured in the first place! Right now, having a dedicated flag that says treat this thing as X turned out to work more reliable for this use case, though we have to figure out a way to set it from the app when you're integrating with existing columns 👍🏻 |
Agree, I didn't think of user-created interfaces.
If you don't have an interface configured, the column should just be treated as being a tinyint, with a normal input field to enter an integer value. |
Is the edgecase on line 130 in |
How about adding some sort of hidden options to the interface configuration which we can use to set the 'special flag'. So a tinyint column is beeing mirrored bij the API as being a tiny int, because that's what it is. No edgecase configuration options in the app are needed, adding a existing column just works the same as adding a new one through directus. Edge case programming in the API is limited to processing the special flag. |
I believe this was resolved in #10083. We can reopen if the problem persists in 9.1.3+ |
I'm having this problem on externally created tables. Tried setting the special field to cast-boolean and still doesn't work. Edit: Ok so after setting the special field to cast-boolean, Directus needs to be restarted. |
I'm also having this problem on externally created tables. Ahhh, I see, the special field has to be |
Preflight Checklist
Describe the Bug
The Toggle interface doesn't work properly when used on a
tinyint(1)
. It will always display the value as disabled (false) even when the tinyint's value is 1.Clicking on it once seems to make it update properly (click once and the value stays at disabled, but the edit page says it can save and update the changes, click once more and the value is set as enabled). But the interface will always be incorrect when opening the edit item page if the
tinyint(1)
value is 1 (true).To Reproduce
tinyint(1)
columntinyint(1)
column1
(enabled)Now the display will show that the value is correctly set to true, but when editing the row the Toggle interface will say the value is not enabled. However, opening it as a raw value shows that the value is correctly set to
1
.What version of Directus are you using?
v9.0.0-rc.95
What version of Node.js are you using?
16.4.0
What database are you using?
MySQL 5.7.34
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying Directus?
Running locally
The text was updated successfully, but these errors were encountered: