Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When the data source of an index contains zero item, running drush sapi-i
prints out:
Couldn't index items. Check the logs for details.
Of course no messages are in the logs, because there were no actual error.
This is just wrong. Let's fix it.
Comment | File | Size | Author |
---|---|---|---|
#12 | 1992684-12-search-api-zero-index.patch | 1.5 KB | janusman |
#1 | 1992684-search-api-zero-index.patch | 1.25 KB | Damien Tournoud |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedI suggest we just remove the condition on zero items indexed. This is just not an error.
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedComment #4
Damien Tournoud CreditAttribution: Damien Tournoud commentedI see that there are actual tests for this, but they are most likely testing the wrong thing.
Comment #5
drunken monkeyIt is an error if there are items to index. The test is therefore correct, too. What you want is a special case for when there are no items to be indexed. The UI doesn't allow indexing in this situation, probably Drush should just do the same.
Comment #6
Damien Tournoud CreditAttribution: Damien Tournoud commentedWell, that's why we have this condition:
I haven't checked, but I'm pretty sure the test would trigger this condition too?
"There is precisely zero item indexed" is a pretty poor error checking condition, as it can really only happen in very very very specific cases (like a fatal PHP error?).
Comment #7
drunken monkeyNot at all. First of all, a fatal PHP error would terminate the page request, and no message at all would be displayed. But if the server configuration is wrong, or the (Solr) server couldn't be reached or in other such cases, indexing will fail completely, not just for some items. And in those cases, it's much more user-friendly to tell users that indexing failed completely instead of displaying "X items could not be indexed" and leaving them to conclude that those were all of the items. If indexing only failed for some items, it's much more likely that something is wrong with the data (or the code handling specific data) – so the two messages tell us two different things.
Comment #8
Damien Tournoud CreditAttribution: Damien Tournoud commented@drunken monkey: well, in that case at the minimum we should store somewhere in the state that indexing has been attempted at all. Due to various race conditions, having indexed zero items can be totally legitimate (say you delete an entity between the batch being registered and the batch executing).
As I said, it's a poor error checking mechanism.
Comment #9
drunken monkeyYou are welcome to provide a patch for that.
Comment #10
jazzslider CreditAttribution: jazzslider commentedSo I'd like to take a stab at explaining why this messaging is problematic. I apologize in advance if there's something significant I'm missing in the following explanation; please feel free to correct me as needed.
The error message "Couldn't index items. Check the logs for details." very strongly implies two things:
However, if you look at the code here, one of those implications is essentially completely false, and the other is often false as well. With my own comments added:
Since the "Couldn't index items" message occurs in cases where the indexing operation _didn't_ encounter any errors, then it seems like we ought to re-think the messaging a bit to remove the confusing implications. Some ideas, which may need tweaking for complete semantic accuracy, but you get the idea:
*
$drupal_set_message($t("No items needed to be indexed. Drupal logs may contain more information."), 'status');
*
$drupal_set_message($t("The indexing operation ran successfully and found no items matching this index's indexing criteria. Drupal logs may contain more information."), 'status');
Again, I'm not 100% certain I've accounted for all the possibilities here, but based on how the code itself reads as well as some of our own troubleshooting on this, I tend to like the second suggestion above more than just about anything. The existing message just causes unnecessary anxiety about whether indexing is actually working, and I'd love to see it changed to avoid that confusion.
If you agree, please let me know if you'd like me to make any additional messaging changes, and I'll be happy to roll a patch.
Comment #11
drunken monkeyI completely disagree with that. The
$success
has little to do with the actual indexing process, but comes from the batch processing. I.e., if$success
isTRUE
nothing went wrong from what the Batch API knows (e.g., you getFALSE
there if you leave the page while the batch is running). Since we do (at least in this case) a good job of catching our exceptions, indexing errors will almost never lead to$success = FALSE
.Instead, if, e.g., Solr could not be reached, or there is another basic error that prevents indexing completely, there is a
SearchApiException
which we catch in_search_api_batch_indexing_callback()
. Unless some items were already indexed before the state changed in a way that made indexing impossible (which is unlikely, but can of course happen), this will result in no items being indexed and thus, in my eyes correctly, in the "Couldn't index items. Check the logs for details." error message.The case that no exception occurred, but still no item was indexed successfully, can only occur under special conditions. If you have those frequently, please describe how to reproduce this and why the error message is confusing in this case. Then we can maybe just add some code when catching the exception to distinguish between the two cases.
When no items need to be indexed, you can either not even execute the batch operation or (when processors like the "Bundle filter" remove all the items) they will still be counted as "indexed" and won't trigger that error message.
Damien's example of deleting the (sole) item just as the batch is started is the only realistic condition I can think of, and I'd say it's far too improbable to change the code for that.
Comment #12
janusman CreditAttribution: janusman at Acquia commentedHere's my proposal.
My assumptions are that, at the end of the batch, this is the information we have:
Because of this, we should never output anything with 'error' level at the end of the batch... we just don't have the needed information.
The patch, thus:
Comment #14
drunken monkeyThat's simply not true, as I've now explained multiple times in this issue. Please try to understand the code before proposing changes.
Comment #15
legolasboThis issue has not seen activity in over 2,5 years. I am therefore closing this issue to clean up the issue queue. Feel free to re-open and update this issue if you feel this issue is still relevant and of importance.
Comment #16
klausiThis error message can be caused by a race condition when search_api_cron() is running at the same time as drush sapi-i. Adding this to our bash script: