Problem/Motivation
If a user could not be created by the ldap module because the ldap user has no mail property the following errors shows up in the watchdog log
Failed to create Drupal account 'SAMAAccount-Property' because email address could not be derived by LDAP User module
But in the user interface the following error show up on near by every admin site:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\ldap_user\Processor\DrupalUserProcessor::drupalUserLogsIn() must implement interface Drupal\user\UserInterface, null given, called in C:\bin\workspaces\Krzn\310_Dinslaken\m310-www\docroot\modules\contrib\ldap\ldap_user\src\Processor\GroupUserUpdateProcessor.php on line 300 in Drupal\ldap_user\Processor\DrupalUserProcessor->drupalUserLogsIn() (line 449 of modules\contrib\ldap\ldap_user\src\Processor\DrupalUserProcessor.php).
Drupal\ldap_user\Processor\DrupalUserProcessor->drupalUserLogsIn(NULL) (Line: 300)
Drupal\ldap_user\Processor\GroupUserUpdateProcessor->processAccount(Object, 'samaccountname') (Line: 244)
Drupal\ldap_user\Processor\GroupUserUpdateProcessor->runQuery('accounts') (Line: 38)
ldap_user_cron()
call_user_func_array('ldap_user_cron', Array) (Line: 392)
Drupal\Core\Extension\ModuleHandler->invoke('ldap_user', 'cron') (Line: 236)
Drupal\Core\Cron->invokeCronHandlers() (Line: 134)
Drupal\Core\Cron->run() (Line: 75)
Drupal\Core\ProxyClass\Cron->run() (Line: 65)
Drupal\automated_cron\EventSubscriber\AutomatedCron->onTerminate(Object, 'kernel.terminate', Object)
call_user_func(Array, Object, 'kernel.terminate', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.terminate', Object) (Line: 88)
Symfony\Component\HttpKernel\HttpKernel->terminate(Object, Object) (Line: 32)
Stack\StackedHttpKernel->terminate(Object, Object) (Line: 686)
Drupal\Core\DrupalKernel->terminate(Object, Object) (Line: 22)
Steps to reproduce
- Create a User without any mail property in you LDAP
- Try to run the cron
Proposed resolution
I think the source have to indentified and a save exit or jump over and log should be considered.
Comments
Comment #2
grahlOn the one hand I'd consider this "working as designed" since this seems to be a missing account name attribute (and not email). Though if it were "mail" the email templates for missing addresses are intended to be used here where accounts are missing that attribute.
But I agree that we can be a bit more graceful here in the bulk updating and not error out in that case.
Comment #3
sunlixIn my case it was the
mailattribute. My colleague has added this to the AD entry and things became fine again. Because the entry was 10 years old and back in that time themailattribute was not a required field.The problem from a usabillity perspective is, that other people manage the AD/LDAP's than the Drupal developer.
In my case a new user was added to the permitted Drupal group but without the
mailattribute.By adding the new user the production system was "broken" (feeling by looking at the error messages printed out).
It would not be that big thing in case the cron would eject or ignore the broken user entry from AD/LDAP.
But it did not end gracefully, so you get the stack trace on any admin page.
Comment #4
grahlComment #5
aaronbaumanSimilar issue here, and it's happening on the latest release.
If I have an LDAP user with an email that already exists in Drupal, what's the suggested workaround here?
Currently ldap_user cron is breaking cron entirely, which is obviously untenable.
Comment #6
rudi teschner commentedIn my opinion the only plausible solution would be to skip the conflicting user, add the proper watchdog message and continue syncing the rest of the users.
Comment #7
aaronbaumanHere's the patch that's working for me.
Setting priority back to Normal, but I could see a case that throwing a fatal during cron run is at least Major.
Comment #8
rudi teschner commentedThe patch is looking good, at first glance it also prevents a warning I got
Comment #9
aaronbaumanFixed the path
Comment #11
aaronbaumanMaybe I can get a MR working instead of a patch...
Comment #14
sergiogsanchez commentedI have tested the patch on Drupal 9.5.5, and it's working as expected skipping the user with errors or not externalauth results
Comment #15
ludo.rPatch #9 works for me.
Comment #16
solideogloria commentedIssues should be marked Fixed after they are committed.