Bug #105817
closedThe fix for #105666 (streamline null and midnight for dbType datetime) was breaking in some cases, and also ignores the TCA default value for datetime
100%
Description
Updating from 12.4.23 to 12.4.24 led to problems in some of our setups, assumingly due to the change in #105666 (assumingly because there were mutliple changes about date fields and this looks the closest one - due to missing time, we were not able to fully debug this in all details, but these are our initial observations.).
We have a table with SQL columns tx_myext_start datetime default null
, the SQL modes strict and NO_ZERO_DATE
are enabled (desired and pre-set by the managed hoster).
The TCA looked before like this (trimmed down to the relevant ones):
'type' => 'datetime',
'dbType' => 'datetime',
'default' => 0,
This worked on TYPO3 12.4.23. Submitted empty datetime fields ended up as NULL
in the SQL DB.
On 12.4.24 trying to save an empty field, however, this leads to
Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column tx_myext_start
The only thing that reliably helped to mitigate this issue on all our servers/DB engines for 12.4.24 (mix of MySQL, MariaDB), was to set these TCA configs:
'type' => 'datetime',
'dbType' => 'datetime',
'format' => 'datetime',
'default' => null,
'nullable' => true,
Especially 'nullable' => true
was the most important one to avoid the SQl error. Isn't the core-default 'nullable' => true
implicitly set if 'dbType' => 'datetime'
? At least this is what happened implicitly up to 12.4.23. Did the change in #105666 alter this (intended or unintended)?
Another observation: setting any non-zero/non-null explicit valid default value, like 'default' => '1234-11-11 04:05:06'
is completly ignored now, no matter what the nullability is set to. I believe this was also introduced with the change for #105666.
Updated by S P about 1 month ago
- Related to Bug #105666: Nullable native time fields store "00:00:00" instead of null if value is unset added
Updated by Benjamin Franzke about 1 month ago
Thanks for your report.
Especially 'nullable' => true was the most important one to avoid the SQl error. Isn't the core-default 'nullable' => true implicitly set if 'dbType' => 'datetime'? At least this is what happened implicitly up to 12.4.23. Did the change in #105666 alter this (intended or unintended)?
The v13 backport implied nullabe=true by default, but since we can not imply that `DEFAULT NULL` is used for native datetime fields in v12 we stayed with nullable=false as default intepretation if TCA does not configure it explicitly in v12.
Given the SQL schema, `nullable` => true is the correct TCA configuration.
I'll try to understand why this worked in your implicit usecase before. I had the perception that it should have always tried to persist 0000-00-00 00:00:00 in that case without explicit nullable=true configuration, but will check that…
Updated by André Buchmann about 1 month ago · Edited
We've got the same error messages on our servers running with MySQL 8.0.27-18 after the Update from 12.4.23 to 12.4.24.
2: SQL error: "SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'product_launch_date' at row 1" (tx_myproducts_domain_model_product:40)
Error occures when the record is saved an has empty datetime fields.
-- ext_tables.sql
CREATE TABLE tx_myproducts_domain_model_product (
product_launch_date datetime DEFAULT NULL,
product_eol_date datetime DEFAULT NULL,
# TCA Field definition
'product_launch_date' => [
'label' => 'product_launch_date',
'config' => [
'dbType' => 'datetime',
'type' => 'datetime',
'size' => 12,
'default' => null,
],
],
'product_eol_date' => [
'displayCond' => $displayconditionIn . $products['image-solution'] . ',' . $products['camera'] . ',' . $products['software'],
'label' => 'product_eol_date',
'config' => [
'dbType' => 'datetime',
'type' => 'datetime',
'size' => 12,
'default' => null,
],
],
After switching my ddev config from MariaDB 10.3 to mysql 8.0 I can also reproduce this error locally.
Update:
Adding 'nullable' => true,
to the TCA configs solves the issue.
Updated by Gerrit Code Review about 1 month ago
- Status changed from New to Under Review
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/87481
Updated by Gerrit Code Review about 1 month ago
Patch set 2 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/87481
Updated by Benjamin Franzke about 1 month ago
This affects v12 only.
I pushed a patch, please test the change to DataHandler in your installations, see:
https://review.typo3.org/c/Packages/TYPO3.CMS/+/87481/2/typo3/sysext/core/Classes/DataHandling/DataHandler.php
Thanks!
Updated by Gerrit Code Review about 1 month ago
Patch set 3 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/87481
Updated by Benjamin Franzke 6 days ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 28f85c28486aefd28695711a9631faf4ae81aa09.