There's a small logic bug in GroupRoleStorage::loadByUserAndGroup() that can lead you to weird results if it is invoked more than once within the same request for a specific user/group combination. The issue is that results are cached locally, but that cache does not vary based on all the method arguments. (i.e. It doesn't account for the $include_implied argument.)
For example, let's say I have group roles A & B in a given group. I invoke loadByUserAndGroup($me, $my_group, TRUE) and I get back something like [A, B, member]. Later within the same request I only want to get those custom group roles, so I invoke loadByUserAndGroup($me, $my_group, FALSE).
Expected:
[A, B]
Actual:
[A, B, member] (the cached result from the previous call)
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | group-2896603-12.patch | 11.61 KB | kristiaanvandeneynde |
| #12 | interdiff-11-12.txt | 1.02 KB | kristiaanvandeneynde |
Comments
Comment #2
kevin.dutra commentedHere's a test that highlights the issue.
Comment #3
kevin.dutra commentedAnd now with the actual fix.
Comment #4
kevin.dutra commentedComment #5
danmuzyka commentedThis looks really good, and the test seems to cover the various combinations of conditions one would expect. Thank you for documenting each scenario in the test so clearly with code comments as well!
Comment #6
mikran commentedThere is also a line
that I stumbled upon while writing access tests for my custom code. This is very closely related to this patch in here and the test is easy to extend for this purpose too so I extended the patch a bit. Sorry that I have to put the issue back to needs review though.
Comment #7
dravenkI was tested this patch. It's working perfect.And, It could be fixed another issues #2906082: Figure out a way to cache lists using group permissions .
Comment #8
skyredwangWe need more review.
Comment #9
kristiaanvandeneyndeUgh crap, I have been working on this myself and only now notice there's an issue for it. The attached patch fixes the problem, introduces a method for clearing the cache and clears it at the right times. Obviously everyone here will receive credit.
Comment #11
kristiaanvandeneyndeMy bad
Comment #12
kristiaanvandeneyndeAnd again... lack of sleep :P
Comment #14
lawxen commentedI use jsonapi to test the patch
jsonapi/group/business&include=field_testIf I use a wrong user/password, I will get
Then If use right user/password, get the same result.
After clear the cache, I will get the right result,
So the patch didn't resolve the cache problem.
Comment #15
kristiaanvandeneyndeThis patch contains zero database caching. So even if clearing the caches solves the problem in #14, it definitely does not seem to be related to the issue in this patch.
This patch is about a static cache, your problem seems to be about a database cache.
Comment #16
kristiaanvandeneynde