I found an issue while I tried to execute the database update on this module.

$ drush updb -y
------------  ----------------  --------------  -------------------------------------
  Module                    Update ID           Type                      Description                                                   
------------  ----------------  --------------  -------------------------------------
  checklistapi                 8001          hook_update_n       Update saved progress configuration to new schema.            
>  [notice] Update started: checklistapi_update_8001
>  [error]  Call to a member function get() on null 
>  [error]  Update failed: checklistapi_update_8001 

After I debugged I found what's happening.

Checklist definition is loaded at line 17 what's working fine but right next it tries to use `->config` public attribute what's null by default.

// Code....
function checklistapi_update_8001() {
   // Code....
   $checklist = checklistapi_checklist_load($id);

   $config = $checklist->config->get(ChecklistapiChecklist::PROGRESS_CONFIG_KEY);
   // Code....

I reviewed `Drupal\checklistapi\ChecklistapiChecklist` class to verify the `$config` attribute, and I also noticed it was marked as deprecated:

  /**
   * The configuration object for saving progress.
   *
   * @var \Drupal\Core\Config\Config
   *
   * @deprecated since version 8.x-1.9, to be removed in 8.x-2.0.
   */
  public $config;
CommentFileSizeAuthor
#2 avoid_error_config_null-3122093-2.patch636 byteskeboca

Comments

keboca created an issue. See original summary.

keboca’s picture

StatusFileSize
new636 bytes

I'm not pretty familiar on how to retrieve the proper configuration object here that's the reason why I added a simple validation to avoid any execution when configuration is not defined what at least it will avoid an error to happen.

mmekut’s picture

Hi keboca, thanks for the patch. i ran into same issue while running DB updates.

Meanwhile you don't need to know how to retrieve the proper configuration object, the maintainer will cross check that on next release.

I found your patch a little awkward so instead of specifically checking for a null object like this

    if (is_null($checklist->config)) {
      continue;
    }

found in your patch file, I did this

    if (!$checklist->config){ 
      continue; // A null object returns false...so skip fetching it
    }

since an undefined, uninitialized OR null object returns false in an if statement

...........and the update ran smoothly

Thanks for the clue

  • TravisCarden committed b38bf47 on 8.x-1.x authored by keboca
    Issue #3122093 by keboca: Call to a member function get() on null at...
traviscarden’s picture

Version: 8.x-1.10 » 8.x-1.x-dev
Status: Active » Fixed

Thanks, @keboca!

Status: Fixed » Closed (fixed)

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