Problem/Motivation
I honestly don't know if this is an issue in version 8*. I found this in a Drupal 7 installation, see https://civicrm.stackexchange.com/questions/49552/membership-statusses-n...
I am surprised I found no bug reports about it here - perhaps they were there in the 7* version.
CRM_Member_BAO_Membership::updateAllMembershipStatus , which is called from scheduled jobs, writes its own record since 5.76. As a result, when CRM_Core_DAO::writeRecord is called, it triggers CRM_Utils_Hook::post which is what `hook_civicrm_post` receives. However, this is now a very shallow object and does not contain a contact_id anymore.
I can see in the 8.* code `civicrm_member_roles_civicrm_post` expects this contact_id. It looks like it will properly fail if it isn't there and not update the associated user. The 7.* seems to fail worse.
Proposed resolution
The shallow `$objref` does contain the membership id. You should be able to find the contact id using that.
Issue fork civicrm_member_roles-3530402
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