Doctrine DriverExceptions after upgrading to NC 20
After upgrading to NC 20 (and the latest NC Spreed/Talk app version), we keep getting Exceptions of type Doctrine\DBAL\Exception\DriverException due to broken SQL INSERT statements triggered by apps/spreed/lib/Chat/Changelog/Manager.php trying to submit the emoji support message:
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\\\\xF0\\\\x9F\\\\x98\\\\x8D' for column `nextcloud`.`comments`.`message` at row 1
There's several strange things to notice:
- It seems pretty obvious that the two hex-escaped bytes representing the emoji cause the problem. Still, manually INSERTing a string with the very same emoji via MariaDB console works without problems. So I'm pretty sure that it's not the database charset/collation settings, that are wrong.
- Table structure of the
commentstable is exactly the same as on a fresh Nextcloud installation, so I'm sure that it's correct. - "Invalid datetime format" sounds like it's about a wrong value to the
comments.creation_timestampfield, but the error message is clear that it's about a wrong value tocomments.message. occ migrations:status spreedshows8000Date20200407115318as current version. Even after manually running migration steps10000Date20200819121721and11000Date20200922161218, it stays that way.
My current assumption is that the emoji bytes are escaped in a wrong way in the doctrine insert statement, but I don't have clue why this should happen and why others don't run into the same problem :thinking:
Talk app
Talk app version: 10.0.1
Server configuration
Operating system: Debian Buster
Web server: Apache
Database: MariaDB 10.3.25-0+deb10u1
PHP version: 7.3
Nextcloud Version: 20.0.1
List of activated apps:
Server log (data/nextcloud.log)
also seen in the server logs here https://github.com/nextcloud/spreed/issues/4462
@doobry-systemli did you upgrade from NC 20.0.0 and Talk 10.0.0 or did you have earlier versions ? Just to find out whether emojis were working correctly before your upgrade
@PVince81 The last upgrade was from NC 20.0.0, where the problem started arising. But I could imagine that the problem existed beforehands, we just didn't notice. We enabled 4-byte support in the database some time back (probably something like a year ago) but to be honest I'm not 100% certain that writing emojis (or whatever multibyte characters) from Nextcloud to the database worked anywhere in the past.
I double-checked everything from the docs about Enabling MySQL 4-byte support. Also, as written above, writing multibyte characters directly to the database (from mysql console) works:
INSERT INTO `comments` (`parent_id`, `topmost_parent_id`, `children_count`, `actor_type`, `actor_id`, `message`, `verb`, `creation_timestamp`, `latest_child_timestamp`, `object_type`, `object_id`, `reference_id`) VALUES(0, 0, 0, "guests", "changelog", "a string with multibyte character emoji: 😍", "comment", NOW(), NULL, "chat", 195, NULL);
That's why I asume that not the database itself is the problem but instead the way how Nextcloud (respectively Doctrine) escapes the multibyte characters in the INSERT statement is somehow broken (on our setup).
I just tested and even trying to add a comment with 😍 to a file triggers the same error, while adding ❤️ (which isn't multi-byte) works. So it's definitely about writing multi-byte emojis to the database. Still INSERTing them directly (as written in the last comment) works as expected.
The code in question is here for the changelog: https://github.com/nextcloud/spreed/blob/master/lib/Chat/Changelog/Manager.php#L88
Strangely it is already checking if the connection supports mb4, and skips that message if it doesn't. Not sure why the CLI one works.
As far as I remember, MariaDB 10.3 supports mb4 by default since 10.3.1
It seems the check only verifies if the charset was set on the connection: https://github.com/nextcloud/server/blob/v20.0.0/lib/private/DB/Connection.php#L427
Not sure if this guarantees that support is there. There's another function that can check it, you could try with the following patch:
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 24b241b78f..ad7bebff3d 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -453,7 +453,15 @@ class Connection extends ReconnectWrapper implements IDBConnection {
if (!$this->getDatabasePlatform() instanceof MySqlPlatform) {
return true;
}
- return $this->getParams()['charset'] === 'utf8mb4';
+ if ($this->getParams()['charset'] !== 'utf8mb4') {
+ return false;
+ }
+
+ $tools = new MySqlTools();
+ if ($tools->supports4ByteCharset($this)) {
+ return true;
+ }
+ return false;
}
note: I don't have an environment to reproduce the issue so I can only guess, the above patch might reveal more information ^
if Talk starts working again but without emojis (check the changelog talk conversation to see if it contains an emoji), it means the DB setup itself has some issues. if Talk doesn't work at all, it means mb4 detection is giving false positives and/or DB setup has issues...
so not sure, we'll see...
Temporary solution otherwise is to delete the following code: https://github.com/nextcloud/spreed/blob/2c1c050ac29ee10068fc9f181db8dbc904f678fe/lib/Chat/Changelog/Manager.php#L88-L94
Thanks, I finally found the issue: it indeed was a missconfiguation of MariaDB. Due to some mistake, character_set_server was set to utf8 (instead of utf8_mb4) and collation_server was set to utf8_general_ci (instead of utf8mb4_general_ci).
So this indeed was a configuration mistake on our side. Big sorry for the noise and many thanks for the debugging hints :heart:
Can @AisukoWasTaken and @htttito confirm that misconfiguration?
Hi, sorry i can not confirm.
- MYSQL is set to utf8_mb4....
- I have delete the code without any result...
- There is always the same error:
`
| Error | no app in context | Exception: Object of class DateTime could not be converted to string/var/www/html/nextcloud/lib/private/AppFramework/App.php - line 157: OC\AppFramework\Http\Dispatcher->dispatch()/var/www/html/nextcloud/lib/private/Route/Router.php - line 308: OC\AppFramework\App::main()/var/www/html/nextcloud/ocs/v1.php - line 88: OC\Route\Router->match()/var/www/html/nextcloud/ocs/v2.php - line 24: require_once("/var/www/ht ... p")Verursacht durchError: Object of class DateTime could not be converted to string/var/www/html/nextcloud/lib/private/Comments/Manager.php - line 786: OC\DB\QueryBuilder\QueryBuilder->execute()/var/www/html/nextcloud/lib/private/Comments/Manager.php - line 749: OC\Comments\Manager->insertQuery()/var/www/html/nextcloud/lib/private/Comments/Manager.php - line 725: OC\Comments\Manager->insert()/var/www/html/nextcloud/apps/spreed/lib/Chat/ChatManager.php - line 117: OC\Comments\Manager->save()/var/www/html/nextcloud/apps/spreed/lib/Chat/SystemMessage/Listener.php - line 282: OCA\Talk\Chat\ChatManager->addSystemMessage()/var/www/html/nextcloud/apps/spreed/lib/Chat/SystemMessage/Listener.php - line 103: OCA\Talk\Chat\SystemMessage\Listener->sendSystemMessage()/var/www/html/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 251: OCA\Talk\Chat\SystemMessage\Listener::OCA\Talk\Chat\SystemMessage{closure}("*** sensiti ... ")/var/www/html/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 73: Symfony\Component\EventDispatcher\EventDispatcher->callListeners()/var/www/html/nextcloud/lib/private/EventDispatcher/EventDispatcher.php - line 86: Symfony\Component\EventDispatcher\EventDispatcher->dispatch()/var/www/html/nextcloud/apps/spreed/lib/Manager.php - line 664: OC\EventDispatcher\EventDispatcher->dispatch()/var/www/html/nextcloud/apps/spreed/lib/Manager.php - line 616: OCA\Talk\Manager->createRoom()/var/www/html/nextcloud/apps/spreed/lib/Chat/Changelog/Manager.php - line 71: OCA\Talk\Manager->getChangelogRoom()/var/www/html/nextcloud/apps/spreed/lib/Chat/Changelog/Listener.php - line 53: OCA\Talk\Chat\Changelog\Manager->updateChangelog("** sensiti ... ")/var/www/html/nextcloud/apps/spreed/lib/Chat/Changelog/Listener.php - line 37: OCA\Talk\Chat\Changelog\Listener->preGetRooms()/var/www/html/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 251: OCA\Talk\Chat\Changelog\Listener::OCA\Talk\Chat\Changelog{closure}("** sensiti ... *")/var/www/html/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php - line 73: Symfony\Component\EventDispatcher\EventDispatcher->callListeners()/var/www/html/nextcloud/lib/private/EventDispatcher/EventDispatcher.php - line 86: Symfony\Component\EventDispatcher\EventDispatcher->dispatch()/var/www/html/nextcloud/apps/spreed/lib/Controller/RoomController.php - line 164: OC\EventDispatcher\EventDispatcher->dispatch()/var/www/html/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 169: OCA\Talk\Controller\RoomController->getRooms()/var/www/html/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 100: OC\AppFramework\Http\Dispatcher->executeController()/var/www/html/nextcloud/lib/private/AppFramework/App.php - line 157: OC\AppFramework\Http\Dispatcher->dispatch()/var/www/html/nextcloud/lib/private/Route/Router.php - line 308: OC\AppFramework\App::main()/var/www/html/nextcloud/ocs/v1.php - line 88: OC\Route\Router->match()/var/www/html/nextcloud/ocs/v2.php - line 24: require_once("/var/www/ht ... p") |
|---|---|---|
| ` |
Enclosed a picture of MYSQL configuration.
Is there any mistake?

Object of class DateTime could not be converted to string
Turn log_query off. The debug code to log queries does not know how to convert a datetime object to string.
I turned logging of...... Still the same error
In Talk, i can only choose the partner to speak or chat.
I can write something in the chat, but when i hit "enter" nothing happens....

Hi Community :-)!
It was my mistake, I mean log_query in mysql....
In nextcloud config.php I changed 'log_query' => false, and all works....
Thanks to all...
I set log_query to false and I still get the same error :/
@nickvergessen cannot confirm misconfiguration.
I have a fresh install, not an upgrade from a lower version of NC or Talk. Mariadb configured as utf8mb4, and so is the database. Setting 'log_query' to false in nextcloud's config.php has no effect.
Server version: 10.3.25-MariaDB-0+deb10u1 Debian 10
MariaDB [(none)]> SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+--------------------------+----------------------------+
Database changed
MariaDB [nextcloud]> SELECT @@character_set_database, @@collation_database;
+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8mb4 | utf8mb4_general_ci |
+--------------------------+----------------------+
Update: Conversations are not permanent, gone if I load talk again. I also cannot post emojis (endless loading circle)~~, and I cannot upload files (this might be a separate issue).~~
That the Talk app does not work after an upgrade to NC20 is probably due to the wrong column formatting in oc_comments.reference_id. I had to add the column manually after an upgrade and looked for the right query here in the forum. Unfortunately, I can't find the entry anymore, it was definitely wrong. After a comparison with a fresh NC20 installation, in which the Talk app worked and the files were not different, the column was created incorrectly and the collation was e.g. not on utf8mb4_bin. After I changed the column correctly, Talk worked again. This does not fix the error with the log_query, but the error with the not starting Talk-App. Hope it helps!
ALTER TABLE oc_comments CHANGE reference_id reference_id VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL;
Fixed with #4730
So will be solved with the next update.