Bug #69084

Epic #68397: Make TYPO3 work with MySQL strict mode

Adding Objects with NOT NULL columns is broken

Added by Morton Jonuschat over 4 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Must have
Category:
Extbase
Target version:
Start date:
2015-08-15
Due date:
% Done:

100%

TYPO3 Version:
7
PHP Version:
5.6
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Using the Blog example from the functional tests it is easy to reproduce with a database that is strict about NOT NULL values (MySQL in strict mode, PostgreSQL and probably any other database that actually cares about data).

When adding a new Blog object the persistence layer tries to first create a new record just consisting of the following fields: crdate,tstamp,pid,sys_language_uid
As there are NOT NULL columns without default values in the table definition of the blog database this leads to constraint validation errors.

MySQL (strict mode) reports: Field 'description' doesn't have a default value
PostgreSQL reports: ERROR: null value in column "description" violates not-null constraint

This seems to originate in \TYPO3\CMS\Extbase\Persistence\Generic\Backend::persistObjects where new objects are treated specially by calling \TYPO3\CMS\Extbase\Persistence\Generic\Backend::insertObject which does not seem to map any of the object properties into the record to be created.

How to reproduce:

1. Add the following line to typo3/sysext/core/Build/Configuration/FunctionalTestsConfiguration.php: 'setDBinit' => 'SET SESSION sql_mode = \'STRICT_ALL_TABLES\';',
2. Run the following functional test: typo3/sysext/extbase/Tests/Functional/Persistence/AddTest.php

It will fail with SqlErrorException: Field 'description' doesn't have a default value


Related issues

Related to TYPO3 Core - Bug #69085: transOrigDiffSourceField ignored by Datamapper Closed 2015-08-15
Related to TYPO3 Core - Bug #69247: Inserting records fails when the model has a incompatible default value Closed 2015-08-21

Associated revisions

Revision 3b5400e6 (diff)
Added by Morton Jonuschat over 4 years ago

[BUGFIX] Extbase: Use fully populated records in Backend::insertObject()

To successfully insert new records into a database that does not
silently convert NULL values being inserted into NOT NULL columns (MySQL
in strict mode, PostgreSQL) it is necessary to use a fully
populated record, even if it contains only placeholders for some fields
like relations or reference counters.

Resolves: #69084
Releases: master
Change-Id: I89e79d59ad53666432e73c3b1651323d0d506ac3
Reviewed-on: http://review.typo3.org/42656
Reviewed-by: Stefan Neufeind <>
Tested-by: Stefan Neufeind <>
Reviewed-by: Alexander Schnitzler <>
Reviewed-by: Daniel Goerz <>
Reviewed-by: Markus Klein <>
Tested-by: Markus Klein <>

Revision 0e37d598 (diff)
Added by Morton Jonuschat over 4 years ago

[FOLLOWUP][BUGFIX] Extbase: Use fully populated records in insertObject()

As it is common practice to define object properties in Extbase models
without default values (resulting in a NULL value) while defining the
database columns as `DEFAULT '' NOT NULL` these columns need to be
skipped when preparing a new record for insertion into the database.
This allows the database to use the configured defaults for columns
not included in the insert statement.

To properly support strict databases in an Extbase extension/model it is
required to configure identical/compatible default values in the
database schema and the model. This problem cannot be solved completely
programmatically.

Resolves: #69247
Related: #69084
Releases: master
Change-Id: I9de6a68a9eac25e171e3bfde6314366dad1ae346
Reviewed-on: http://review.typo3.org/42821
Reviewed-by: Markus Klein <>
Reviewed-by: Wouter Wolters <>
Tested-by: Markus Klein <>
Reviewed-by: Anja Leichsenring <>
Tested-by: Anja Leichsenring <>

History

#1 Updated by Morton Jonuschat over 4 years ago

  • Status changed from New to In Progress
  • Assignee set to Morton Jonuschat
  • Parent task set to #68

#2 Updated by Morton Jonuschat over 4 years ago

  • Parent task changed from #68 to #68397

#3 Updated by Gerrit Code Review over 4 years ago

  • Status changed from In Progress to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42656

#4 Updated by Gerrit Code Review over 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42656

#5 Updated by Morton Jonuschat over 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#6 Updated by Riccardo De Contardi about 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF