| Project: | Entity reference |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Not sure why, but all the way up to the initial commit of this module, we have had target_id defined as:
<?php
'target_id' => array(
'description' => 'The id of the target entity',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
?>The column accepts NULL as a value, which is legitimate in some corner cases (the Tree module uses this to store roots of the tree, but it already can modify the schema itself), but most of the cases it just hides obscure bugs.
For example in #1569046: Handling NULL values during the migration of Entity Reference fields, we have a case of a migration storing NULL values in there incorrectly, which result in:
The target_id => NULL causes all kinds of EntityMalformedExceptions, hinders indexing by Solr and causes this kind of warnings: Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()
I think we should just consider moving to NOT NULL and this type of issue would have been caught way sooner.
Comments
#1
> we have a case of a migration storing NULL values in there incorrectly
I think we should follow core here, and keep it not NULL:
$schema['taxonomy_term_data'] = array('description' => 'Stores term information.',
'fields' => array(
'tid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique term ID.',
),
although maybe I miss a case where it's indeed needed to be NULL?
#2
oh, I've misread the title -- yes it should be
'not NULL' => TRUE#3
Ok, changing this is relatively trivial. Here is a patch.
#4
#5
Merged into 7.x-1.x.
#6
Correct update process.
#7
Correct update process.
Sorry for the double comment
#8
Right, update fails in rc2 (Missing argument 4 for db_change_field()). Patch from #7 solves this.
#9
Thanks for the patch. Upgrade with drush now works
#10
Shame. I was certain I tested that. Let's roll a rc3 :(
#11
Automatically closed -- issue fixed for 2 weeks with no activity.