Problem/Motivation

When updating from 10.25 to 10.30 or 10.31 (on two populated installations) - I had errors updating the database.

The issue turned out to be this:
"Call to a member function getFieldValue() on null in /var/www/social/html/profiles/contrib/social/modules/social_features/social_event/modules/social_event_invite/social_event_invite.tokens.inc on line 88"

If I just make sure $message isn't null, I can successfully update the database.

replace
$event_enrollment = $storage->load($message->getFieldValue('field_message_related_object', 'target_id'));
with
if ($message){
$event_enrollment = $storage->load($message->getFieldValue('field_message_related_object', 'target_id'));
}

If I remove this check after updating, I get the same error (getFieldValue() on null) when I try to enroll in an event. So it's not just a problem on updating the database.

This change gets things working for me, but I'm not sure why it's only an issue on older existing sites and I don't know if a bigger fix is necessary as to why $message is null.

Steps to reproduce

Updating from social 10.25 to 10.30 or 10.31 (perhaps with events with enrollments?)

Proposed resolution

Make sure adding the if ($message) is an appropriate solution.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#6 3246751-6.patch1.28 KBmilos.kroulik

Comments

dereks created an issue. See original summary.

ressinel’s picture

Hello @dereks

I cannot reproduce this. Could you provide more information?

dereks’s picture

@Ressinel - I didn't have trouble on a fresh install on the same box, but two sites that have been running Open Social for a few years, with my own occasional tweaks, wouldn't update. So it's probably something I did - I just don't know what.

Is there any harm in just checking if $message is null? Or is that a necessary variable, and will break things elsewhere if it's missing?

skatheeth’s picture

Hello All,

I am also facing the same exact issue reported by @dereks above.

When updating from 10.25 to 10.30 or 10.31 I am getting this error:

This same error comes from many other files like the ones listed below as all of them call this function "getFieldValue"
Can someone please help on this issue.

Error: Call to undefined method Drupal\message\Entity\Message::getFieldValue() in Drupal\social_activity\EmailTokenServices->getRelatedObject() (line 76 of profiles\contrib\social\modules\social_features\social_activity\src\EmailTokenServices.php)

  1. social\modules\social_features\social_group\social_group.module
  2. social\modules\social_features\social_group\modules\social_group_default_route\social_group_default_route.module
  3. social\modules\social_features\social_group\modules\social_group_default_route\src\EventSubscriber\RedirectSubscriber.php
  4. social\modules\social_features\social_group\modules\social_group_flexible_group\src\Access\FlexibleGroupContentAccessCheck.php
  5. social\modules\social_features\social_group\src\CacheContext\SocialGroupJoinMethodCacheContext.php

SOLUTION : core\lib\Drupal\Core\Entity\ContentEntityBase.php file have a function missing which was present in earlier version before running composer update. Once i re-added the function it solved the issue.

  public function getFieldValue($field_name, $property) 

Does Open Social manipulates this code in CORE? Because as per record ContentEntityBase.php has not been changed in 2 years

milos.kroulik’s picture

Perhaps there should be an issue for each problem? Regarding the missing

getFieldValue()

method - it was added by patches in https://www.drupal.org/project/drupal/issues/2580551. Perhaps OS used patch from that issue and in 10.3 no longer does so?

milos.kroulik’s picture

StatusFileSize
new1.28 KB

Temporary patch fixing the missing message key.

bmango’s picture

Wow, perfect timing! The patch worked perfectly. I was upgrading from 10.3.1 to 10.3.2 and got this error.

The patch also fixed another update for social_group_update_10308 which had the same error: Call to a member function getFieldValue() on null.

Thanks so much for the patch.

ronaldtebrake’s picture

@#5 we indeed use that patch, and we still do in 10.3 & will be in 11
See: https://github.com/goalgorilla/open_social/blob/main/composer.json#L41

In this case I think the provided patch should be something we can add, it's at least some good defensive measurement.
We might need to think about what we want to do if the actual message isn't there as this will likely just render the token itself, but in this way it at least doesn't break.

ressinel’s picture

@milos.kroulik Thanks for your patch!

I have created PR with your changes but made some adjustments: https://github.com/goalgorilla/open_social/pull/2633

ressinel’s picture

Status: Active » Needs work
ressinel’s picture

Status: Needs work » Needs review
milos.kroulik’s picture

Status: Needs review » Needs work

This needs further fix, because current solution still throws a notice: Undefined index: message social_event_invite.tokens.inc:83

Something like this is needed at line 83:

$message = isset($data['message']) ? $data['message'] : null;
tbsiqueira’s picture

Status: Needs work » Fixed

  • ronaldtebrake committed 76de44f on 10.3.x
    Issue #3246751 by milos.kroulik, Ressinel: Add extra check for Message...
  • ronaldtebrake committed 80a7f83 on 10.3.x
    Issue #3246751 by milos.kroulik, Ressinel: Add extra check for Message...
  • ronaldtebrake committed dc61bb5 on 10.3.x
    Issue #3246751 by milos.kroulik, Ressinel: Add extra check for Message...

  • ronaldtebrake committed 5221891 on 11.0.x
    Issue #3246751 by milos.kroulik, Ressinel: Add extra check for Message...
  • ronaldtebrake committed 8d4cfb0 on 11.0.x
    Issue #3246751 by milos.kroulik, Ressinel: Add extra check for Message...
  • ronaldtebrake committed c47490d on 11.0.x
    Issue #3246751 by milos.kroulik, Ressinel: Add extra check for Message...

Status: Fixed » Closed (fixed)

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