Problem/Motivation
There is one query to the Database whose value ends up sent as "null" and Drupal Database connection class throws a warning:
Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike() (line 1525 of core/lib/Drupal/Core/Database/Connection.php).
Drupal\Core\Database\Connection->escapeLike(NULL) (Line: 420)
Drupal\Core\Database\Query\Select->escapeLike(NULL) (Line: 118)
...
Steps to reproduce
Using fivestar module with PHP8.1
Proposed resolution
Check for empty variables with "empty" function or similar instead of boolean "!" operator.
Remaining tasks
-
User interface changes
-
API changes
-
Data model changes
-
Issue fork fivestar-3324052
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dpavon commentedHi, this is the first time I commit through the UI, so take it with a grain of salt.
As for the query / code change itself, I would assume we don't want to perform the queries if the values are NULL, since the warning would then show up.
If, however, the query needs to be run with some of these parameters as optional, then instead we will need to replace the "NULL" values for empty strings or don't add the property so that on PHP8.1 we don't get the warning.
I will continue testing the module to gather this context that I lack right now. I guess we'd normally need entity_type at all times, but entity_id could be optional. However, contextually wise I'd prefer to have both so we can properly evaluate if the user can re-vote an entity. I don't see the value for now on having empty values intentionally.
Comment #4
dpavon commentedHmm, I checked a bit more the code, and the lines that review that entity_id and entity_type are not empty are far below and return TRUE.
I took the change to refactor some more lines and commited anew. I'll re-test.
Comment #5
o'briatIs it related to the Drupal 10 compatibility?
Shall I merge this commit into the Automated Drupal 10 compatibility fixes MR ?
Comment #7
heddnThis fixes the underlying issue by always providing the context information to the render element.
Comment #8
heddnComment #9
tr commentedThe accessCheck issue is #3391088: Error: Entity queries must explicitly set whether the query should be access checked or not and that fix should be handled in the issue that describes that problem. It should NOT be mixed in with this unrelated issue. We already have far too many issues that all conflict with each other because they all mix in random unrelated code changes.
Comment #10
tr commentedYes, the correct way to fix this error from addcslashes() is to make sure the variables used always have a value.
There are at least five other issues that make many of these same changes surrounding the userCanVote() method. And part of the problem is that the changes in Voting API from D7 to D8, namely the renaming of content_id/content_type to entity_id/entity_type do not seem to be fully reflected in the current Fivestar code.
But if these changes are to be made, they shouldn't be made in isolation - all those other issues need to be looked at and the comments read to ensure this is being changed in the right way and not in a way that we already know doesn't work. Likewise it would be nice to give credit to the people who did the work on those other issues, rather than just throwing away their contributions. In fact IMO it's highly likely that this addcslashes() issue is just a side-effect of an already-known problem and will disappear as a result of fixing those other issues.
Comment #11
heddnRebased MR on HEAD and changed from content_* to entity_* wording as per #10.
Comment #12
heddnAnd now with test coverage.
Comment #13
wxman commentedI'm getting nothing but the error on any page that has Fivestar. I'm using the alpha4 release, but I don't get which MR or patch I should be using? It's a bit confusing. Thanks
Comment #14
heddnMR 14 (https://git.drupalcode.org/project/fivestar/-/merge_requests/14.patch) should fix the issue.
Comment #15
wxman commented@heddn Sorry to be a pain. I added the patch and ran this:
My composer.json looks like this in the extra section:
Sometimes I miss the obvious.
Comment #16
heddnLet's just merge this and tag a new release.
Comment #18
heddnhttps://www.drupal.org/project/fivestar/releases/8.x-1.0-alpha5
Comment #19
wxman commented@heddn when you update the branch like that do we leave the patch in as is, or remove it and just run composer require 'drupal/fivestar:^1.0@alpha'
Comment #20
heddnNormally you would leave the patch file in, but now you can just `composer update` and get alpha5 and remove all patches.
Comment #21
wxman commented@heddn That did it! No errors, and I can edit the star ratings. You folks are great.
Comment #22
ivnish