Problem/Motivation
Drupal\Component\Plugin\Exception\ContextException: The 'entity:user' context is required and not present. in Drupal\Core\Plugin\Context\Context->getContextValue() (line 73 of core\lib\Drupal\Core\Plugin\Context\Context.php).
Upgrading to Drupal 9.3.0 or higher versions from 9.2.10 does something to the uid column that locks the users out of the site. I couldn't log in with my administrator account after the upgrade so I had to reset the password using a php reset script. When I finally was able to log in, every row in 'admin/people' tab was empty except for the account that was created during Drupal installation. Please see attached screenshot.
Additionally, the site wasn't accessible to anonymous users after the upgrade. I had to manually add an anonymous user with uid 0 to solve that problem.
All of the users are basically locked out meaning their credentials do not work after the upgrade. I am running 4 Drupal instances on the same platform (Windows Server + MSSQL DB). I've had similar issues with all of them after the upgrade.
I found a thread that is possibly related.
https://www.drupal.org/project/drupal/issues/3258118#:~:text=The%20under....
Drupal 9.3.0 introduced some database changes and user role dependencies - https://www.drupal.org/project/drupal/releases/9.3.0#:~:text=User%20role...
I wonder if that has anything to do with it. Any idea when we might get a patch/version release to tackle this issue?
Steps to reproduce
1) Upgrade to Drupal 9.3.x from Drupal 9.2.10
2) Run update.php script through the URL
3) Try to log in once the database update is complete
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | userid definition error.png | 9.09 KB | rramirezsn |
| screenshot.png | 20.68 KB | devKhairul |
Issue fork sqlsrv-3263493
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
Comment #2
devKhairul commentedComment #3
devKhairul commented@Beakerboy @david_garcia
Anything?
Comment #4
alexpott@devKhairul I can confirm that there is a problem with updating from Drupal 9.2 to 9.3 with the SQL server driver.
The problem is because we can't create a new identity column on a table and set the values as we want to. Therefore we have a tricky issue to solve. After updating from 9.2 to 9.3 there is no user with UID 0 anymore.
Here is a work around that fixes my local test site. Use with caution and please please please backup your database first. But this does have a chance of fixing your site if you have run 9.3 database updates on an SQL server backed site.
Here's the SQL to run against your database:
Comment #5
alexpott@devKhairul note looking at the issue summary it appears you've manually added a user with the UID of 0. You'll need to change the SQL to
to cope with that.
Comment #6
devKhairul commented@alexpott
Thanks for your input. Much appreciated. I'll give that a try. Any idea when we might be getting a patch for this issue or will it be addressed in the newer version of the module?
Comment #7
alexpott@devKhairul well we've updated core today to not run the update that breaks stuff on SqlServer - see #3265802: user_update_9301() causes data loss and a broken site on SQL Server and the plan now is to add an update to the sqlsrv module that does the change. The current plan is to do that in this issue so you should see the patch / MR arrive here and then be committed... hopefully that'll be soon.
We have another related MySQL 8 issue to fix on Drupal 9.3.x before we might do an off-schedule Drupal 9 release to ensure no one else breaks their site due to this, if D9 release managers agree to this.
@devKhairul hopefully you didn't do the update on live and are still running on Drupal 9.2.x - that's still under security support so I'd hold on trying to upgrade until sqlsrv is updated to account for the update.
Comment #8
devKhairul commented@alexpott
That's great news!! I haven't updated the production sites to 9.3.x yet. We're still on 9.2.12. I'm going to hold off until we have a permanent solution since 9.2.x is due to receive security coverage until June. It makes sense to me to just wait and do the upgrade when the solution is officially committed to the module.
Comment #9
devKhairul commented@alexpott
Any update on this? Thank you!!!
Comment #10
alexpott@devKhairul I spoke to @beakerboy about this - I thought he had some ideas.
Comment #11
chrisckHello just wanted to toss my hat in the ring for this issue. We've attempted a Drupal 9.3 upgrade in mid-December last year and ran into the same error:
Drupal\Component\Plugin\Exception\ContextException: The 'entity:user' context is required and not present. in Drupal\Core\Plugin\Context\Context->getContextValue() (line 73 of core\lib\Drupal\Core\Plugin\Context\Context.php).
We could not figure out what the problem was and rolled back to Drupal 9.2.x as a temporary measure. After tracing multiple Drupal threads from Drupal core issue queue, I've landed here, which is promising. I've pasted in the error code in h2 tags to help with searchability for others having the same issue.
Drupal 9.2.15
Microsoft-IIS/10.0
SQLServer 13.00.4001
PHP 7.4.8
Comment #12
chrisckUpdating issue with error message to help with searchability.
Comment #13
devKhairul commented@alexpott Thank you!! I hope @beakerboy has some good news for us in store.
Comment #14
devKhairul commented@alexpott - Is there a way to submit a request to extend security coverage for Drupal 9.2.4 in case we don't have a solution in the next months?
Comment #17
KenKodz commentedI've been working with @beakerboy in my attempt to fix the changeField method to support changing a field to serial when there is existing data in the table. This requires the following to occur:
If anyone has any recommendations to improve this, please let me know. I am still learning MS SQL and Drupal.
Comment #18
KenKodz commentedOne thing to note, once this is code is merged, we still need to get the core team to update
user_update_9301in theuser.installfile to allow it to run if the new version of the module or greater is installed.Comment #19
alexpott@KenLewis - I don't think you will need the core team to do anything - the sqlsrv module can provide its own update - we already stopped running the update for sqlsrv - see #3265802: user_update_9301() causes data loss and a broken site on SQL Server . I don't think we can revert that change because we need to be sure that the latest sqlsrv module is being used.
Comment #20
alexpott@KenLewis I'd also be tempted to be pragmatic here and implement something like #4 in a update function in sqlsrv for now - and implement a generic fix later. It's more important to get people to 9.3.x than to have a generic fix.
Comment #21
devKhairul commentedHello, any update on this?
Comment #22
devKhairul commented@KenLewis @alexpott - Hi guys, do you guys have any information regarding this? We haven't heard anything in a while. We are still running 9.2 but 9.4 is out. We'd appreciate some insight so we can make an informed decision. :)
Comment #23
devKhairul commentedUpdate:
So after months of waiting, I went ahead and decided to upgrade to Drupal 9.4.5 from 9.2.21.
* The upgrades were successful. However, it didn't upgrade the user module so you get a red-hot error when you go to the 'status report' page.
* I can no longer add new users to the site. I assume this is because the user module upgrade was skipped.
The site is working well so far. These are however tiny sites. I have two huge sites that I'm planning to upgrade soon. I'll see how that goes.
I don't know what consequences await for me but I guess I'll wait and see.
Comment #24
pstewart commentedHaving read through this issue, it looks like the following actions are needed to resolve:
user_update_9301. This update function should ensure it only attempts to do work if the column is not already an appropriate identity column in the database (i.e. if the site admin has already fixed the schema manually to work round the problem while awaiting the fix from this issue).Is this correct?
Comment #25
devKhairul commented@pstewart
I think number 2 will fix the problem with the user table. I could not find any way to manually fix the schema to get around the problem.
Comment #26
rramirezsn commentedHi:
I ran to this same issue when upgrading a production site from 9.2 to 9.5.
After the database update there was not posible to create users so i fixed the schema manually to work around the problem but now i had a error on the site state report:
No coinciden las definiciones de entidad y/o campo
Se detectaron los siguientes cambios en las definiciones de tipo de entidad y de campo.
Usuario
El campo ID de Usuario necesita ser actualizado.
Any idea how to solve it?
Comment #27
solideogloria commentedThe translation of the above comment:
Entity and/or field definitions do not match
The following changes were detected in the entity type and field definitions.
User
The User ID field needs to be updated.
Comment #29
solideogloria commentedUpdating target branch
Comment #30
solideogloria commentedComment #33
pstewart commentedNoting that most of the discussion has been happening on #3371473: SQL Server Identity error when updating to Drupal 10.1.0, which includes successful testing of MR87. The merge request will be completed on this issue and once this issue has been closed as fixed the other issue will be closed as duplicate.
Comment #36
solideogloria commentedShould this now be closed as Fixed?
Comment #37
pstewart commentedI'm planning to mark all the issues resolved in 4.4.x as fixed when we do the stable release, which will hopefully be the same as rc1 if no problems arise.
Comment #38
pstewart commented