Deprecated function addcslashes() warning caused by empty value

Created on 28 November 2022, almost 2 years ago
Updated 4 October 2023, 12 months ago

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

-

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain dpavon

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France O'Briat Nantes

    Is it related to the Drupal 10 compatibility?
    Shall I merge this commit into the Automated Drupal 10 compatibility fixes πŸ“Œ Drupal 10 compatibility fixes Fixed MR ?

  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 12 months ago
    4 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 12 months ago
    4 pass
  • heddn Nicaragua

    This fixes the underlying issue by always providing the context information to the render element.

  • Status changed to Needs review 12 months ago
  • Status changed to Needs work 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    The accessCheck issue is πŸ› Error: Entity queries must explicitly set whether the query should be access checked or not Active and that fix should be handled in the issue that describes that problem. It should NOT be mixed in with this unrelated issue.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Yes, 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.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 12 months ago
    4 pass
  • heddn Nicaragua

    Rebased MR on HEAD and changed from content_* to entity_* wording as per #10.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 12 months ago
    4 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 12 months ago
    6 pass
  • Status changed to Needs review 12 months ago
  • heddn Nicaragua

    And now with test coverage.

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    I'm getting nothing but the error on any page that has Fivestar. I'm using the alph4 release, but I don't get which MR or patch I should be using? It's a bit confusing. Thanks

  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @heddn Sorry to be a pain. I added the patch and ran this:

    @server2:~/newsite$ composer require 'drupal/fivestar:^1.0@alpha'
    ./composer.json has been updated
    Running composer update drupal/fivestar
    Gathering patches for root package.
    Removing package drupal/fivestar so that it can be re-installed and re-patched.
      - Removing drupal/fivestar (1.0.0-alpha4)
    Deleting web/modules/contrib/fivestar - deleted
    Loading composer repositories with package information
    Updating dependencies
    Nothing to modify in lock file
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 0 updates, 0 removals
    Gathering patches for root package.
    Gathering patches for dependencies. This might take a minute.
      - Installing drupal/fivestar (1.0.0-alpha4): Extracting archive
      - Applying patches for drupal/fivestar
        https://git.drupalcode.org/project/fivestar/-/merge_requests/14.patch (#3324052 Deprecated function addcslashes)
       Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/fivestar/-/merge_requests/14.patch
        https://www.drupal.org/files/issues/2023-10-02/fivestar-access-check-3391088-2.patch (#3391088 Entity queries must explicitly set)
    
    

    My composer.json looks like this in the extra section:

        "extra": {
            "patches": {
                "drupal/fivestar": {
                    "#3324052 Deprecated function addcslashes": "https://git.drupalcode.org/project/fivestar/-/merge_requests/14.patch",
                    "#3391088 Entity queries must explicitly set": "https://www.drupal.org/files/issues/2023-10-02/fivestar-access-check-3391088-2.patch"
                    }
            },
    

    Sometimes I miss the obvious.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 12 months ago
    6 pass
  • Status changed to Fixed 12 months ago
  • heddn Nicaragua

    Let's just merge this and tag a new release.

    • heddn β†’ committed 83df5c02 on 8.x-1.x
      Issue #3324052 by heddn, dpavon, TR, wxman: Deprecated function...
  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @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'

  • heddn Nicaragua

    Normally you would leave the patch file in, but now you can just `composer update` and get alpha5 and remove all patches.

  • Status changed to Needs review 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States wxman

    @heddn That did it! No errors, and I can edit the star ratings. You folks are great.

  • Status changed to Fixed 12 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024