Project

General

Profile

Actions

Feature #91688

closed

TCA: Make default value mandatory for some field types if SQL field defined as "NOT NULL" - avoid error in extensions due to strict and missing default

Added by Sybille Peters over 4 years ago. Updated 5 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2020-06-22
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

I propose to generate a warning if TCA does not have a default value and the field is defined as "NOT NULL" in ext_tables.sql

For some fields, this may not be necessary (e.g. select, passthrough).

Fields where it could be checked: e.g. input.

To be honest, I have not entirely figured out when it is a problem and will create an error and when a default is set automatically.

See also Stack Overflow questions:

  1. TYPO3: SQL error: 'Incorrect integer value: '' for column 'sys_language_uid' at row 1'
  2. How to set default values correctly in TCA to avoid strict error messages and when is it necessary? (without answer)

An alternative solution might be that the TCA default value is automatically set correctly due to the type of the DB field.


Newer Versions of MySQL / MariaDB have strict (STRICT_TRANS_TABLES) by default.

If you have the SQL field defined as NOT NULL and no default is set via TCA, you might get an error like this:

SQL error: Field `something` doesn't have a default value

I had this problem with ods_osm (which has now been patched, so it is not resproducible anymore).

Reproduce

  1. Set your database to strict, e.g. sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION, ...
  2. Use extension ods_osm
  3. Remove the default line in TCA overrides for fe_groups https://github.com/bobosch/ods_osm/blob/master/Configuration/TCA/Overrides/fe_groups.php
  4. Clear cache
  5. Create a new FE group

You should now see the above error


The problem with missing defaults is only a problem with extensions as the core does not have the problem because it sets the defaults correctly. However, I think this setting might prevent problems in the future where extension authors test with a database server without strict setting and may not be aware of the problem their extension might be causing.

With other systems, it is enough to define the table schema with a default value. With TYPO3 it is not enough.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #88331: MySQL strict mode: let integer time fields be filled with NULLClosed2019-05-10

Actions
Actions #1

Updated by Rémy DANIEL almost 4 years ago

  • Related to Bug #88331: MySQL strict mode: let integer time fields be filled with NULL added
Actions #2

Updated by Sybille Peters 5 months ago

  • Status changed from New to Closed

Closing due to:

- no watchers
- no comments
- no Status "Accepted"
- open since 2020

There were some problems when DB server started using "strict" by default but these could all be solved by modifying the TCA in extensions. Since then, the problem is no longer as relevant and perhaps not necessary to add additional checks in the core.

Actions

Also available in: Atom PDF