Describe the bug
The user data contained a 馃檪 in one of the fields. When the model was saved, the following error occured:
Integrity constraint violation: 4025 CONSTRAINT properties failed for db_name.activity_log
So this is caused by the CHECK (json_valid(properties)) constraint. The smiley is not valid json, and probably should be encoded first.
I just removed the field from the logAttributes array as I don't really require the field to be logged. But maybe this helps improve this great package!
Versions (please complete the following information)
Without further debugging I would say that this is a bug in Laravel/Eloquent core as we don't serialize/encode the JSON ourselves but use the Eloquent cast logic to do so. 馃
I will add a testcase and check if we can reproduce it. Possibly it's also a problem with MariaDB or something similar.
Thanks!
I don't know how Laravel handles this internally, but according to PHP docs this should be used:
json_encode( $text, JSON_UNESCAPED_UNICODE );
I never used this myself, just from the docs. Maybe this helps.
Hey, after trying it my own and searching a bit it seems like your MariaDB setup isn't emoji compatible. 馃
Modern databases can handle emojis with and without escaping as long as the used character set allows it.
https://stackoverflow.com/questions/55437104/minimal-setup-for-mariadb-to-handle-emojis
Could you check this? As there's really nothing we could do in the package. And the Laravel core itself is also emoji compatible as long as the database is.
TLDR: you were right, it was a db issue. It only manifests in older version of MariaDB.
I did a full investigation of the problem:
properties))" and after that had no issues. The resulting record was exactly the same as in the other MariaDB versions. Conclusion:
This probably was a bug in an older version of MariaDB in the json_valid function.
Just for reference, the statement not working in the old version of MariaDB was:
INSERT INTO activity_log (log_name, description, subject_type, subject_id, causer_type, causer_id, properties, created_at, updated_at) VALUES ('default', 'updated', 'test\Models\User', 99229, 'test\Models\User', 1, '{\"attributes\":{\"memo\":\"Have fun play fast \ud83d\ude42\"},\"old\":{\"memo\":\"old\"}}', '2021-01-10 17:26:59', '2021-01-10 17:26:59');
Result:
4025 - CONSTRAINT properties failed for xxxx.activity_log, Time: 0.031000s
Thanks for your time and effort!
Most helpful comment
TLDR: you were right, it was a db issue. It only manifests in older version of MariaDB.
I did a full investigation of the problem:
properties))" and after that had no issues. The resulting record was exactly the same as in the other MariaDB versions.Conclusion:
This probably was a bug in an older version of MariaDB in the json_valid function.
Just for reference, the statement not working in the old version of MariaDB was:
INSERT INTO
activity_log(log_name,description,subject_type,subject_id,causer_type,causer_id,properties,created_at,updated_at) VALUES ('default', 'updated', 'test\Models\User', 99229, 'test\Models\User', 1, '{\"attributes\":{\"memo\":\"Have fun play fast \ud83d\ude42\"},\"old\":{\"memo\":\"old\"}}', '2021-01-10 17:26:59', '2021-01-10 17:26:59');Result:
4025 - CONSTRAINT
propertiesfailed forxxxx.activity_log, Time: 0.031000sThanks for your time and effort!