Project

General

Profile

Actions

Bug #88515

closed

Cannot unset DateTime value via null

Added by Mathias Brodala about 5 years ago. Updated 8 days ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2019-06-07
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Given an Extbase domain model with a DateTime property and a DB field declared as usual:

my_date int(11) unsigned DEFAULT '0' NOT NULL

Setting a value here from a Fluid form works fine and the date is stored as timestamp in the DB.

However, when trying to clear this property, an SqlException occurs:

(1/1) #1470230767 TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException
Column 'my_date' cannot be null

in /.../typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php line 197

The error occurs when Backend::persistObject() calls DataMapper::getPlainValue() with the current null value for the DateTime property and thus gets a string "NULL" in return. This then fails because null values are not allowed here in SQL.

An override of AbstractDomainObject::_getProperties() with a fallback to 0 (zero) for date properties works around the issue, however this should be fixed in Extbase itself:

public function _getProperties(): array
{
    $properties = parent::_getProperties();
    $properties['myDate'] ??= 0;

    return $properties;
}

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #103641: Not possible so set nullable relation values in extbase domain modelsClosedTorben Hansen2024-04-16

Actions
Actions #1

Updated by Alexander Schnitzler over 4 years ago

  • Status changed from New to Accepted
  • Is Regression set to No

The correct default type is also dependent on the db type option set in the TCA. The one that determines if a field should be treated as an integer or datetime.

Actions #2

Updated by Mathias Brodala over 2 years ago

  • Description updated (diff)
Actions #3

Updated by Mathias Brodala over 2 years ago

  • Description updated (diff)
Actions #4

Updated by Alexander Schnitzler over 2 years ago

How does the property definition look like? Is null the default value here?

Actions #5

Updated by Claus Harup over 2 years ago

Yes - NULL is the default value:

I had:

/**
* @var Ship|null
*/
protected ?Ship $ship = null;

....

/**
* @return array
*/
public function _getProperties(): array
{
   $properties = parent::_getProperties();
   $properties['ship'] ??= 0;

   return $properties;
}
Actions #6

Updated by Jan Kornblum over 1 year ago

Still same issue in 10 LTS...

Actions #7

Updated by Torben Hansen 3 months ago

  • Related to Bug #103641: Not possible so set nullable relation values in extbase domain models added
Actions #8

Updated by Bastian Stargazer 21 days ago

  • TYPO3 Version changed from 9 to 11

Issue still exists in v11.5.36

If the time is never set for a record, the (default) value is 0 in the database. If the field is once set via new \DateTime() in Extbase and saved, it is impossible to reset the field back to 0 in the database. This is a huge problem!

Actions #9

Updated by Garvin Hicking 21 days ago

  • Status changed from Accepted to Resolved

I believe this is solved via https://forge.typo3.org/issues/103641

I will close this issue for now, if you feel this is a mistake or have additional feedback, please get in touch. You can also create a follow-up issue.

Actions #10

Updated by Benni Mack 8 days ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF