This was supposed to be fixed in https://www.drupal.org/node/1107522 but appears not to be the case.
My schema structure for field in question is:
'n_factor' => array(
'description' => 'Factor for converting nitrogen to protein.',
'type' => 'numeric',
'precision' => 4,
'scale' => 2,
'unsigned' => TRUE,
'not null' => FALSE,
),
The desired effect from import is that if the feed item contains empty value for that field, it should result in NULL but it appears to be trying to pass an empty string and resulting in the following error in feeds log:
SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: '' for column 'n_factor' at row 1
Original item
array(
'ndb_no' => '09383',
'fdgrp_cd' => '0900',
'long_desc' => 'Tangerines, (mandarin oranges), canned, juice pack, drained',
'shrt_desc' => 'TANGERINES,(MANDARIN ORANGES),CND,JUC PK,DRND',
'comname' => '',
'manufacname' => '',
'survey' => 'Y',
'ref_desc' => '',
'refuse' => '0',
'sciname' => '',
'n_factor' => '',
'pro_factor' => '3.36',
'fat_factor' => '8.37',
'cho_factor' => '3.7',
)
Entity
(object) array(
'vid' => '17307',
'uid' => '0',
'title' => 'Tangerines, (mandarin oranges), canned, juice pack, drained',
'log' => 'Updated by FeedsNodeProcessor',
'status' => '1',
'comment' => '0',
'promote' => '1',
'sticky' => '0',
'nid' => '17307',
'type' => 'food',
'language' => 'und',
'created' => '1442946028',
'changed' => 1442946033,
'tnid' => '0',
'translate' => '0',
'revision_timestamp' => '1442946033',
'revision_uid' => '1',
'name' => '',
'picture' => '0',
'date' => '2015-09-22 12:20:28 -0600',
'revision' => FALSE,
'is_new' => FALSE,
'timestamp' => 1442946033,
)
I can pass NULL as value if field is empty on manual node add/edit and database gets updated accurately so not sure what the issue is with feeds import... Is there anything i can do in the target callback function to only set value if there is one? I've tried checking for empty in if clause and seems to be ignored.
function food_import_n_factor ($source, $entity, $target, $value, $mapping) {
$entity->$target = $value;
}
Comment | File | Size | Author |
---|---|---|---|
#4 | FOOD_DES_0.xml_.zip | 11.68 KB | apmsooner |
#4 | feed_importer.txt | 4.98 KB | apmsooner |
#4 | food.zip | 11.93 KB | apmsooner |
Comments
Comment #2
apmsooner CreditAttribution: apmsooner commentedI think what I'm ultimately trying to get at is, if my table allows a null value and I explicitly set NULL as value in the target callback for empty $value, why is feeds kicking back an error and skipping the feed item?
My callback function:
Again, my defaults in form with NULL as fallback for empty field works fine and no problems saving node. Not sure what part of feeds module may be interrupting what I would expect to happen.
Comment #3
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedI have tried to reproduce this, but I didn't got this error. I tried it with both a decimal and a float field and the following XML file:
Can you provide the following:
Comment #4
apmsooner CreditAttribution: apmsooner commented@MegaChriz,
Thanks for helping out. Just to clarify, my module creates a node type of "food" that has a custom table that gets filled/updated upon node save so the fields in question are not CCK fields but rather from a custom table. Attached is my module as well as the feeds importer. I'm using Feeds XPath Parser for the feed however i've tried doing it as csv as well and the same errors occur. I've attached small sample xml file as well for testing.
Note: i know i could set values to 0 for empty result and would import just fine but that is undesirable for my needs. As you will see, manually saving a new node or existing node with empty decimal field returns NULL as desired. Feeds seems to bypass that and make it conform otherwise. I've tried playing with the feeds target callback to return NULL if empty but it seems to be ignored. I appreciate any workaround suggestions if you know of any....
Thanks!
Comment #5
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedThe fourth parameter of the mapping target callback
$value
is an array since Feeds 7.x-2.0-beta1. This was done to handle multivalued fields in consistent way. Therefore, your node object will for example become$node->food_n_factor = array(0 => '')
. See also the change record.Since your targets are single-valued, you could change your code to the following, for example:
And instead of the hook
hook_feeds_processor_targets_alter()
you can now also use the hookhook_feeds_processor_targets()
to specify new targets.Comment #6
apmsooner CreditAttribution: apmsooner commentedThanks for the reply @MegaChriz, first off I tried your suggestion but the result is only some of the items get imported and the rest signal an error of "Missing bundle property on entity of type node."
Is the above example proper syntax? The documentation is difficult to decipher on proper useage... perhaps i'm missing something simple.
Additionally, tried changing to hook_feeds_processor_targets and get an error for paramater 1 being supplied as value. Again, where exactly is the documentation for this new hook?
Thanks
Comment #7
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedThe documentation for the hook
hook_feeds_processor_targets
is in feeds.api.php. It has one parameter less.Comment #8
apmsooner CreditAttribution: apmsooner commentedJust wanted to post back that by changing to proper parameters for hook_feeds_preprocessor_targets as outlined above is now working for me. Additionally, my decimal fields are importing just fine now as null values if empty in source. I didn't need to reset $value but rather just pull $value out of the $values array and seems to not be an issue for me anymore. I suppose the new function is what has fixed all this up for me now. Here is my callback revision for reference:
Thanks for all the help MegaChriz!
Comment #9
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedThe reset() function just returns the first element of an array. It does not make changes to anything what is in the array.
Comment #10
apmsooner CreditAttribution: apmsooner commentedAhh! okay, i misunderstood its use. Thanks for the clarification.