In #2137317: Some questions about aggregator in d8 , dasjo said:
also note that aggregator fails when a feed item contains an empty description:
Drupal\Core\Entity\EntityStorageException: SQLSTATE[HY000]: General error: 1364 Field 'description' doesn't have a default value: INSERT INTO {aggregator_item} (iid, description, fid, title, langcode, link, author, timestamp, guid) VALUES (default, default, :db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => 18 [:db_insert_placeholder_1] => ... [:db_insert_placeholder_2] => und [:db_insert_placeholder_3] => ... [:db_insert_placeholder_4] => ... [:db_insert_placeholder_5] => 1338129317 [:db_insert_placeholder_6] => ... at ... ) in Drupal\Core\Entity\FieldableDatabaseStorageController->save() (line 693 of /../core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php).
ParisLiaskos said:
Ugh, that bug needs an issue for sure.
I ran into this issue trying to add my personal delicious feed to Aggregator. Steps to reproduce, assuming you have a feed that has items with no description:
- Add the feed as a new feed at admin/config/services/aggregator
- Click "Update items" under "Operations"
Comments
Comment #1
eelkeblokI attached a patch that solves the problem. The NULL value is explicitly set in the Zend\Feed\Reader\Entry\Rss in case of an empty value. I was not 100% sure where would be the appropriate location to test for the NULL value, but since author and timestamp had similar mechanisms, I thought this should be OK.
Comment #2
eelkeblokComment #3
eelkeblokOne question remains, btw; should we also allow for the other fields to be NULL (i.e. title, guid and link)?
Comment #4
ParisLiakos commentedthanks for the patch!
But i think that this check should happen in the processor instead before calling setDescription to the item entity.
I think you are right..i think we should also check for the link and also maybe the guid for being null before setting them.
Also we should add a test for this
Comment #5
eelkeblokNot the title? Obviously, especially when all of them would be empty something is up, but we shouldn't break on a database update then, I guess.
Either way, thanks for your input. This is my first core patch, so tests wasn't something on my radar, but I realized later that would probably be required too. I'll have a crack at that too, this seems like a simple enough issue to serve as an "introduction to core patches" study subject :)
Comment #6
ParisLiakos commentedOh, welcome then, and thanks for your contribution!
About the title:
This is in the processor^
For tests, adding an entry in
core/modules/aggregator/tests/modules/aggregator_test/aggregator_test_rss091.xmlwith no description should be enough.
Btw i just added an entry like this:
It only complained about the description. no problem about the empty link or empty author
Comment #7
eelkeblokOK, here's another stab, with additions to the test feed to trigger the problem. I added a few more items to the feed, basically one item with all fields empty, and then one for each case where one field is empty, assuming that would cover any possible combination of empty fields. This to catch any problems like this down the line. As you found, it was only needed to take special action for the empty description, at this point.
Edit: Whoops, I misnumbered the patch.
Comment #9
eelkeblokAh, that's a shame, the patch trips up the test "Remove feed item functionality" with the message "Total items in feed equal to the total items in database (4 != 7)". I did re-run all aggregator tests, not sure why I didn't pick this up. Probably at least the items with a missing title should not be in the feed with "valid" items because of the code in #6. That leaves one item unaccounted for. Indeed, needs work.
Comment #10
eelkeblokComment #11
eelkeblokIt was a simple fix, really, the failing test was asserting on the number of items imported from the feed, which obviously changed with the extra test cases.
Comment #13
ParisLiakos commented11: core-aggregator-empty-item-description-2187233-11.patch queued for re-testing.
Comment #14
ParisLiakos commentedExactly:)
Thank you!!
Comment #15
alexpottNice find. Committed 134cfbe and pushed to 8.x. Thanks!