Problem/Motivation

When we run the CRON command it is interrupted by the error below:
[error] TypeError: Drupal\node_revision_delete\NodeRevisionDelete::getCandidatesRevisionsByNumber(): Argument #1 ($number) must be of type int, null given, called in /var/www/docroot/modules/contrib/node_revision_delete/node_revision_delete.module on line 308 in Drupal\node_revision_delete\NodeRevisionDelete->getCandidatesRevisionsByNumber() (line 287 of /var/www/docroot/modules/contrib/node_revision_delete/src/NodeRevisionDelete.php) #0 /var/www/docroot/modules/contrib/node_revision_delete/node_revision_delete.module(308): Drupal\node_revision_delete\NodeRevisionDelete->getCandidatesRevisionsByNumber(NULL)

Steps to reproduce

We recently updated the Drupal core to version 9.4.8 along with the site studio core to version 6.9
Everything works perfectly on the site, but when running the Cron command, the error occurs.

Proposed resolution

Add a check to the variable checking if it received any value or NULL

Remaining tasks

User interface changes

API changes

Data model changes

Comments

cleversonr created an issue. See original summary.

cleversonr’s picture

To resolve this issue, make the changes below to the node_revision_delete.settings.yml file:

_core:
  default_config_hash: RASH GENERATED AUTOMATICALLY
delete_newer: false
node_revision_delete_cron: 50
node_revision_delete_time: -1
node_revision_delete_minimum_age_to_delete_time:
  max_number: 12
  time: months
node_revision_delete_when_to_delete_time:
  max_number: 12
  time: months
eric_a’s picture

Title: Error with node_revision_delete when run cron command » Error with node_revision_delete when candidates number is NULL
Version: 8.x-1.0-rc5 » 8.x-1.x-dev
Component: Drush commands » Code
Assigned: cleversonr » eric_a
Priority: Normal » Critical

Yes, I think this fatal error was introduced with 1.0.0-RC5.
Assuming that @cleversonr is not working on a patch or merge request I'm re-assigning this issue and will try to come up with a fix today.

eric_a’s picture

Title: Error with node_revision_delete when candidates number is NULL » Error with node_revision_delete when node_revision_delete_cron is NULL
Assigned: eric_a » Unassigned
Status: Active » Needs review
StatusFileSize
new759 bytes

I guess that before the RC5 type declarations the NULL value was juggled to int 0 at some point. (If not, then possibly all valid revisions were attempted to be deleted at cron time.) If so then it's logical to just do the same here. The simplest would be to add 0 as a default to the get('node_revision_delete_cron').
But really, during cron run it just doesn't seem logical to continue querying and processing if the value is NULL, unless I'm misreading the docs and completely misunderstanding the intent of the code. Same for the 0 value, but I think it is best to just fix the fatal here and leave the 0 case for a separate issue, especially since the NULL is a new fatal, in one place, while the 0 case already existed, in multiple places in the code base.

To trigger this error one must succeed in setting node_revision_delete_cron to the NULL value, which is certainly possible. (And probably easier before RC5.)

adriancid’s picture

Status: Needs review » Fixed

Thanks

  • adriancid committed 4f15ce3 on 8.x-1.x
    Issue #3320816 by Eric_A, cleversonr, adriancid: Error with...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.