Closed (fixed)
Project:
Search API
Version:
8.x-1.x-dev
Component:
General code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Sep 2022 at 15:07 UTC
Updated:
11 Nov 2023 at 11:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
indefinitedevil commentedOn further inspection of the issue, I can see the issue continues with the following substr functions. As such, I have amended the patch to account for those issues.
Comment #3
phannphong commentedThe patch file seems ok with me. Thanks indefinitedevil
Comment #4
szato commentedThank you, patch solved the issue.
Comment #6
drunken monkeyThanks a lot for posting this issue and patch!
However, the docs for
\Drupal\search_api\Utility\Utility::splitPropertyPath()already specify that$property_pathhas to be astring, even though we apparently didn’t have scalar type hints available at the time to write this directly into the method signature.It would therefore be interesting to know what code calls this method with
$property_path = NULL, so we might instead just fix that code. Would you be able to get the backtrace for these calls?Comment #7
drunken monkeyIs anyone running into this able to provide a backtrace?
Comment #8
kleiton_rodrigues commentedThe patch #2 looks good!
+1 RTBC
Comment #9
drunken monkeyAs said, please provide a backtrace so we can get to the real root cause here. Just masking the problem is usually not the wisest approach.
Comment #10
drunken monkeyComment #11
admirlju commented@drunken monkey hope this helps. What I've noticed anytime the cache is cleared this error pops up.
Comment #12
admirlju commentedSo looking a bit into it, right after the php error search API I also get:
Drupal\search_api\SearchApiException while adding Views handlers for field on index Content index dev: Could not retrieve data definition for field '' on index 'Content index dev'. in Drupal\search_api\Item\Field->getDataDefinition() (line 482 of /var/www/html/web/modules/contrib/search_api/src/Item/Field.php).Now the weird part is I have no clue where I'm getting a field with an empty string label.
Comment #13
admirlju commentedOkay, so even more digging it looks like this happens with 3 special fields
search_api_id,search_api_language, andsearch_api_datasourceand it could potentially happen because of the backend I'm usingSearch API Meilisearch. But I'm not sure what the original issue was using, so hard to tell if it's down to the backend.Edit: To clarify these 3 fields are automatically being indexed by that backend.
Drupal\search_api\Item\Field->getDataDefinition()gets called only every field after clearing the cache. This is when the mentioned special fields show up here. Looking atDrupal\search_api\Backend::getSpecialFields()this is when they are created and in the $field_info onlytypeandoriginal typeare provided. I assume this is normal since these fields are not mapped to anything.Comment #14
sarwan_verma commentedHello @indefinitedevil,
I have fixed this issue PHP 8.1 Deprecated Function , some other issues resolve and also created patch,
please review and verify.
Comment #16
admirlju commented@sarwan_verma So for some reason the tests are failing, but that said the specific fix meant for this issue is the same as the original patch file, and that does work. But the maintainer wants to fix this problem at the root cause, method docs requires that parameter to already be a string and not NULL.
Comment #18
admirlju commentedSo the NULL check is not a good solution, if you just do that you'll still get this in the dblog:
Drupal\search_api\SearchApiException while adding Views handlers for field on index Content index dev: Could not retrieve data definition for field '' on index 'Content index dev'. in Drupal\search_api\Item\Field->getDataDefinition() (line 482 of /var/www/html/web/modules/contrib/search_api/src/Item/Field.php).While it fixes the depreciation error, you are still getting a SearchApiException that is correctly handled and logged.
Here I've made a small change in the
search_api.views.incfile at least for my case it fixes it, could someone please test the patch file? Thanks.Comment #19
admirlju commentedComment #20
admirlju commentedComment #21
drunken monkeyThanks for the backtrace and the additional information!
The problem indeed seems to come from the Meilisearch backend. I don’t think it’s smart to include those special fields there, since it might confuse users.
That being said, it seems
search_api_views_data()already guards against fields with no property path, and_search_api_views_get_handlers()just fails to do the same. So I think this is still also a bug in this module.The attached patch should fix it, please test/review! It also adds a check in
\Drupal\search_api\Item\Field::getDataDefinition()to avoid callingretrieveNestedProperty()with aNULLproperty path, which should help debug if this problem ever arises again.Note: The patch requires PHP 8.0, but that should really be required at this point. (It apparently even is for Drupal 9, without me noticing it.)
Comment #22
admirlju commentedThe provided patch fixes the deprecation issue, so this can probably be merged. So now with the meilisearch, this error pops up since the special fields are indexed there, so I guess the added debugging code also works:
I will be opening an issue on the Search API Meilisearch module about this, but I'm not sure if is it ok to index these fields or not.
If it's ok what would be the correct approach?(Fixed it there)That said I'm setting this issue as RTBC.
Comment #24
drunken monkeyGood to hear, thanks for testing!
Merged. Thanks again!