-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Predict entity access cache contexts #584
Comments
@awm086 found the same problem with tmgmt. |
Thanks. I tried step in debug to see what is building the cache context but could not figure out where the contexts are being added, any pointers perhaps I could give it a shot myself? |
The problem is that cache contexts are simply not predictable, since they may be altered in any alter hook, access check and who knows where else. We tried to predict them because this would allow us to check cache metadata automatically (thats the exception that jumped into everybody's face), but unfortunately it didn't work out. Instead I reverted to the old solution that basically gets cache contexts from the result itself and stores them in a second cache that is keyed by the input query and arguments. |
I applied this patch on 8.x-3.0-beta7 (which is identical to 8.x-3.0) and now it is better but still some issues:
Then, on the second request (refresh) the results are returned properly. |
@awm086 Can you give me an example of a query where this happens? |
Any query, with tmgmt_content enabled.
|
Sounds like one of the nasty cases where a Drupal module is invalidly tapping into the rendering system when e.g. resolving entity access, etc. without being asked to do so. Spaghetti mess. We've wrapped some resolvers into rendering context buckets before (remember @pmelab?!). Seems like we have to extend that to other resolvers again. I wish people would follow conventions ... |
I also opened an d.o issue for tmgmt at https://www.drupal.org/project/tmgmt/issues/2966165. Not sure if we have suggestions for the module maintainer. |
I replied on that issue as well. It's neither graphql nor tmgmt at fault here. It's a conceptual problem with how cache contexts were designed within the cache system for D8. |
I merged your PR @pmelab. The other issue left here is unrelated (leaking render cache metadata). We might want to go back to wrapping EVERY resolver into a render context. Not sure if that impacts performance at all. If it doesn't we should do it. |
Is there a way for a developer to resolve this issue in a custom module? Even if it's not the ideal way to do so. |
…dering. Fix error reported drupal-graphql#584 which causes an error: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early.
I attempted to fix it and used a similar approach of the earlier version please see PR referenced above and let me know if that's an OK way to go about it. |
This should be resolved now. Thanks @awm086 |
I added a test case (see #588) and I don't think this is resolved properly.
|
Sorry, my bad. Complete oversight on my part. 2 is quite bad indeed :P. |
The problem is that #588 alone does not solve it adequately because it simply drops all cache metadata that was previously leaked. |
I also don't see the leaking metadata error, but 70% of all tests fail. Perhaps we should follow a more structured approach. |
Pushed a new attempt. @awm086 I'm sorry, could you test this one again? |
Yeah I just played around with it. I don't have a worikng laptop atm. 🤣 |
@pmelab Edit2: Appologies again, I am using the d.o version and it may not have all the updates: |
Cache contexts are not predicted properly. Right now we just hardcode the
user.node_grants:view
context for nodes. Paragraphs for example include the parent entities access result, and we can't hardcode that. But there must be a way to predict cache contexts for access results.The text was updated successfully, but these errors were encountered: