-
-
Notifications
You must be signed in to change notification settings - Fork 213
getEmptyValueByFieldType returns NULL value by mistake #8477
Comments
|
@contao/developers /cc |
|
I was able to reproduce it with: $GLOBALS['TL_DCA']['tl_content']['fields']['test_field'] = array(
'eval' => array('doNotCopy' => true),
'sql' => "varbinary(128) NOT NULL default ''",
);Which results in a “Query error: Column 'test_field' cannot be null” when trying to duplicate a content element. I think we should remove Widget.php:1529-1532 to fix this issue. |
This way we wouldn't get NULL as the empty value for a varbinary field (or blob etc.) even if it was a valid value. I suggest that, instead of elseif (in_array($type, array('binary', 'varbinary', 'tinyblob', 'blob', 'mediumblob', 'longblob')))
{
return null;
}we use something like elseif (in_array($type, array('binary', 'varbinary', 'tinyblob', 'blob', 'mediumblob', 'longblob')))
{
return strpos($sql, 'NOT NULL') === false ? null : '';
} |
|
Fixed in 073c1c3. |
|
@vstuber no I think definitions like if (strpos($sql, 'NULL') !== false && strpos($sql, 'NOT NULL') === false)
{
return null;
}before that. |
|
I think we can improve this further if we change if (strpos($sql, 'NULL') !== false && strpos($sql, 'NOT NULL') === false)to if (strpos($sql, 'NOT NULL') === false)because |
|
Then `tstamp` int(10) default '0'In this case |
Which would be right, because |
|
Then I guess the method should have been called https://github.com/contao/core/blob/master/system/modules/core/classes/Versions.php#L291 |
|
But for |
|
Maybe. Anyway, the purpose of the existing method is to convert an empty string into the suitable empty value depending on the field type. And we are expecting it to return |
|
Then I don’t see the problem with my suggested change. All |
|
True. |
|
Changed in cce5e51. |
### 4.2.4 (2016-09-21) * Handle special character passwords in the "close account" module (see contao/core#8455). * Handle broken SVG files in the Image and File class (see contao/core#8470). * Reduce the maximum field length by the file extension length (see contao/core#8472). * Fall back to the field name if there is no label (see contao/core#8461). * Do not assume NULL by default for binary fields (see contao/core#8477). * Correctly render the diff view if not the latest version is active (see contao/core#8481). * Update the list of countries and languages (see contao/core#8453). * Correctly set up the MooTools CDN URL (see contao/core#8458). * Also check the URL length when determining the search URL (see contao/core#8460). * Only regenerate the session ID upon login.
|
FYI I'm using the same in the Doctrine integration: aschempp/contao-core-bundle@e7fc254#diff-ecdfb51ac371b19aded651b8b47ff381R138 You might want to use |
|
Changed in cff4c1a. I also applied |
The function "getEmptyValueByFieldType" first checks whether the field's sql definition contains "NULL" but not "NOT NULL" and returns NULL if this is the case. If it's not, the function checks whether the field has one of the following types: 'binary', 'varbinary', 'tinyblob', 'blob', 'mediumblob', 'longblob'.
If it does, NULL is returned, even though the function never made sure that NULL is actually allowed for this field.
A field defined as "varbinary(128) NOT NULL default ''" causes the function to return NULL which results in a fatal error when this value is written to the database.
Some extensions still use field definitions like this, especially since for quite some time this was contao's definition for alias fields, which, of course, has also been used by extension developers.
Since Contao 3.5.14 (I think) this function is also used when copying records in the backend which means that copying db records with varbinary alias fields causes the system to crash.
The text was updated successfully, but these errors were encountered: