Problem/Motivation

I updated my Drupal to 9.3.6 from 9.1.8. In that process I updated the Flag and Flag Lists.

My previous version of Flag List was 4.0.0.-rc1. After the update, it's now Flag 4.0.0-rc2

Steps to reproduce

When you go to home page and click on the My flagging Collection main menu (/flagging_collection), it shows following error:

The website encountered an unexpected error. Please try again later.
Error: Call to a member function id() on null in Drupal\flag_lists\Access\FlaggingCollectionAccessControlHandler->checkAccess() (line 24 of modules/contrib/flag_lists/src/Access/FlaggingCollectionAccessControlHandler.php).

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

npcoder created an issue. See original summary.

sl27257’s picture

Do you have the possibility to check if the -dev has the solution for this? If so I will push that ASAP.

BR

/Thomas

npcoder’s picture

@sl27257: I uninstalled the flag_lists:^4.0@RC and reinstall flag_lists:4.0.x-dev@dev using composer.
I got the same error.

sl27257’s picture

That you don't see any difference with the -dev indicates that you should have seen some kind of error earlier...

What I mean is that (sorry for the joke) "this error can't occur". So there must be something wrong with the database, because a Flagging Collection must have an owner. And checking for the owner should be a standard procedure.

Did you see any error when upgrading to rc2?

Have you removed any users from your installation?

The next step to trace your error would be to dig into your database to understand why there is a problem with the user. Do you have the possibility to run MySQL code?

/Thomas

tlwatson’s picture

I'm getting the same error on the Modules page after upgrading from 4.0.0.-rc1 to 4.0.x-dev (to get past the getUsername error for D9).

In fact, I'm getting a whole swath of errors when upgrading to dev. When I ran drush updb I got:
Call to a member function id() on null

/admin/modules :
Error: Call to a member function id() on null in Drupal\flag_lists\Permissions\FlagListsPermissionHandler->getPermissions() (line 52 of modules/contrib/flag_lists/src/Permissions/FlagListsPermissionHandler.php).

/flagging_collection :
Error: Call to a member function label() on null in Drupal\flag_lists\FlaggingCollectionListBuilder->buildRow() (line 80 of modules/contrib/flag_lists/src/FlaggingCollectionListBuilder.php).

/admin/structure/flags :
Error: Call to a member function getDisplayName() on null in Drupal\flag_lists\FlagListsFlagListBuilder->buildRow() (line 112 of modules/contrib/flag_lists/src/FlagListsFlagListBuilder.php).

Obviously for the time being I won't be using dev, but I've got at least one non-functioning admin page as it is...
It is very likely that users got deleted, but flags and flag lists/collections ought to be deleted along with them. If they do now but perhaps that was not the case in the past, could you provide a script to run for us to clean out orphaned flag list data? (I'd try to do it in the DB myself but I'd be nervous about missing something unless there's a proper delete/cleanup method).

sl27257’s picture

Assigned: Unassigned » sl27257

I have now been able to reproduce the original error described. I did this by removing a user. There are four different possible ways to remove a user. Where I am using this module the heaviest the policy is to only inactivate the users, not to remove them. So I have never thought of this...

What is missing is a hook_ENTITY_predelete that remove all flagging collections belonging to a user when the user is deleted. There has never been such a functionality but of course there should be. There are two way of doing it, which is selectable when removing the user, either they are deleted or they are move to user 0, the anonymous user.

For the completeness I will also add an update in the code that fixes the orphaned flagging collections, flags and flag list items. That is the proper way to do it.

Regarding the errors in #5 the two first doesn't seem to be related to this. The the third definitely is.

sl27257’s picture

Here is a "complete" patch. Please check it out!

It fixes the removal of users. It also contain two updates for removing orphaned Flag List Items and Flagging Collections due to removed users.

sl27257’s picture

StatusFileSize
new5.66 KB

Hmmm, forgot to remove some debug dpm's... New try...

sl27257’s picture

Status: Active » Needs review
npcoder’s picture

Thank you @sl27257 for the brief explanation of the issue. Now, I remember that I might have deleted some users.
Though I've not tested the patch you provided, I guess it must work as you have clearly described the cause of the issue. I will let you know.
Thank you!

npcoder’s picture

@sl27257: The error still exists after applying your patches.

These were the errors and patches I made:

Error #1:
The website encountered an unexpected error. Please try again later.
Error: Call to a member function id() on null in flag_lists_flag_action_access() (line 244 of modules/contrib/flag_lists/flag_lists.module).

Solution:

L:243
if ($flagList->getRelatedFlag() !== NULL) {
...
...
}

Error #2:
The website encountered an unexpected error. Please try again later.
Error: Call to a member function id() on null in Drupal\flag_lists\FlagListsFlagLinkBuilder->build() (line 88 of modules/contrib/flag_lists/src/FlagListsFlagLinkBuilder.php).

Solution:
L: 88

if ($flagList->getRelatedFlag() !== NULL) {
...
...
}

I have attached the patch file too. After the above changes, my project ran.

npcoder’s picture

After #11 fix, I again got another issue

The website encountered an unexpected error. Please try again later.
Error: Call to a member function id() on null in Drupal\flag_lists\Permissions\FlagListsPermissionHandler->getPermissions() (line 52 of modules/contrib/flag_lists/src/Permissions/FlagListsPermissionHandler.php).

I have added a patch for this issue.

npcoder’s picture

StatusFileSize
new7.14 KB
sl27257’s picture

A question: Did you execute the update 8005?

npcoder’s picture

@sl27257 Yes I had.

sl27257’s picture

Unfortunately your patches doesn't fix the problem. They only mask it. The basic problem, which is an error in the database still is there.

I have some guesses what is causing them for some of the cases.

Error #1:

This I hope is fixed by #3257955: Error: Call to a member function isSyncing() on null in flag_lists_actions_flagging_collection_presave() (line 71 of modules/contrib/flag_lists/modules/flag_lists_actions/flag_lists_actions.module). This is NOT in rc2 but requires the dev. The easiest way to check it would be to disable the sub-module for action which is possible with the -dev. Are you using the actions?

For the others they might be related to #12 last sentence in #3257955: Error: Call to a member function isSyncing() on null in flag_lists_actions_flagging_collection_presave() (line 71 of modules/contrib/flag_lists/modules/flag_lists_actions/flag_lists_actions.module). Disable the sub module action and then re-enable it if you need it.

I would like to take it from there and see if they still remain.

/Thomas

BTW: Let me know if I shall make a "complete" dev-module with everything in it. There are some important issues missing currently.

npcoder’s picture

Thanks, @sl27257 for the response.
I'm sure it's related to the database table, where I might have deleted some content that might be linked with the flag_lists. Once I have turned the tables using a DB tool (DBeaver).

I added those patches which I created and it worked.

Yes, that would be great, creating a dev-module with everything in it, and let's give it a try.

Thanks.

  • sl27257 committed 90be429 on 4.0.x
    Issue #3266427 by npcoder, sl27257: Call to a member function id() on...
sl27257’s picture

@npcoder!

I have assessed your corrections. From a user point the work because the error messages are hidden from the end user. But they mask a severe error in the database, which shouldn't (must not) be there and that will affect the behavior of the module. So that is why I don't have included them yet. A compromise, as I see it, one solution would be to add your code but instead of not executing the code add a error message to the log, for the administrator.

Either

"This error should not be here"

(old style Unix message :) )

"You have an error in your database, please investigate"

(more correct wording)

What are your comments to this?

BR

/Thomas

  • sl27257 committed 45306af on 4.0.x
    Issue #3266427 by npcoder, sl27257: Call to a member function id() on...
sl27257’s picture

Two more places found where an empty related Flag protection could be needed.

  • sl27257 committed 62292ec on 4.0.x
    Issue #3266427 by npcoder, sl27257: Call to a member function id() on...
sl27257’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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