-
Notifications
You must be signed in to change notification settings - Fork 471
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
Fix encoding error on columns when using Trilogy #466
base: master
Are you sure you want to change the base?
Conversation
It happens when 2 columns are selected, one of which is a JSON type with non-ASCII characteres (eg: Japanese). Blazer will try render the entire template in UTF-8 and that field in ASCII-8BIT. Error: ``` ActionView::Template::Error incompatible character encodings: UTF-8 and ASCII-8BIT ``` Tested on MySQL 5.7.
Hi @D-system, thanks for the PR. However, I'm not able to reproduce the error (without it). SELECT CAST('["え"]' AS JSON) AS a, 'test' AS b Can you share a simple query that causes the error? |
Hi @ankane I known it was to bit me that I didn't include the code to reproduce the bug. Table setup and value: CREATE TABLE `blazer_466` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`string_value` varchar(255) DEFAULT NULL,
`json_value` json DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5018188 DEFAULT CHARSET=utf8mb4;
INSERT INTO `blazer_466` (`string_value`, `json_value`, `created_at`, `updated_at`)
VALUES ('あ', '\"[{\\\"name\\\":\\\"あ\\\"}]\"', '2024-01-26 10:10:12', '2024-01-26 10:10:12');
Both In Blazer (working query):select id,
-- string_value,
json_value
from blazer_466
limit 2 In Blazer (not working query):select id,
string_value,
json_value
from blazer_466
limit 2 Stack
|
Regarding low details implementation, for
I'm on Rails 6.1, so I use the activerecord-trilogy-adapter gem |
Thanks @D-system, was able to reproduce it with that example. Spent some time on this today, but don't have a great solution. Converting all strings to UTF-8 will fail with SELECT b'11111111'; We could convert strings with |
I reproduced the binary issue. Even the |
Pushed a fix for the error in the commit above, but don't have a good way to show the JSON value. Edit: One way would be to manually cast in queries - |
I feel that json fields are more used then binary fields. Json is readable by default, binary is not. If there's a manual effort to do, personally I would put the effort on the non-readable fields (the binary). |
That would be ideal, but don't see a good way to do that and fix the errors. May revert and leave things as is (since it only affects some queries). |
It happens when 2 columns are selected, one of which is a JSON type with non-ASCII characteres (eg: Japanese). Blazer will try render the entire template in UTF-8 and that field in ASCII-8BIT.
Error:
Tested on MySQL 5.7.
My current workaround that I deployed is: