Problem/Motivation
When a user enters an invalid Drupal.org username during registration, the following fatal error occurs:
Error: Call to a member function __isset() on null in Drupal\do_username\DOUserInfoRetriever->isValidUser() (line 79 of modules/contrib/do_username/src/DOUserInfoRetriever.php)
This happens because the code attempts to call __isset() on a null value when the user validation fails.
Steps to reproduce
- Install the do_username module.
- Configure a field using the module in a user profile (e.g., using the Profile module).
- Visit the user registration page.
- Enter an invalid Drupal.org username.
- Submit the form.
Expected behavior: A validation message should appear stating that the username is invalid.
Actual behavior: A fatal error is thrown.
Proposed resolution
Add a null check to ensure that getUserInformation() returns a valid value before calling __isset() or any other method on it.
Remaining tasks
- Add null check in
DOUserInfoRetriever::isValidUser().
- Write/update test coverage (if applicable).
- Review and merge the patch.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
divyansh commentedSplit null check and method call to prevent fatal error when getUserInformation() returns NULL for non-existent drupal.org users.
Comment #3
divyansh commentedComment #4
divyansh commentedComment #5
bhogue commentedCan confirm.
I replicated issue on a DrupalPod environment, getting the same error as above when entering an invalid Drupal.org username using the field provided by the module.
After applying the patch and again supplying an invalid Drupal.org username, an error message appears on the form and the field is highlighted as an error.
Comment #6
divyansh commentedComment #7
nicxvan commentedI think this also happens when drupal.org is down like on Tuesday.