Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
If a pager for a given view display has an offset, this offset is subtracted from the rowcount to calculate the $total_items value. If the rowcount < the offset, this results in a negative value.
Since $total_items is disclosed as token in view display areas as e.g. "@total" this looks like a (minor) bug to me.
Proposed resolution
Simple fix: never let $total_items be negative.
Comment | File | Size | Author |
---|---|---|---|
#32 | 2881030-32.patch | 2.11 KB | Manuel Garcia |
#32 | interdiff.txt | 1.29 KB | Manuel Garcia |
#28 | 2881030-28.patch | 1.89 KB | pk188 |
#26 | interdiff-9-19.txt | 560 bytes | pk188 |
#22 | interdiff-9-19.patch | 644 bytes | Manuel Garcia |
Comments
Comment #2
keesje CreditAttribution: keesje commentedComment #3
dawehnerIt would be nice if we have some form of test coverage here?
Comment #4
keesje CreditAttribution: keesje commentedI will try to provide that, but need some guiding. I would suggest:
run testExecuteCountQueryWithOffset multiple times with 2 sets of data?
like:
3 rows, offset 2 asserts 1
2 rows, offset 3 asserts 0
Or
make a new testcase for this in PagerPluginBaseTest?
like:
testExecuteCountQueryWithOffsetLargerThanResult()
Comment #5
dawehnerThis sounds super nice!
Comment #6
keesje CreditAttribution: keesje commentedAdd testcoverage
Comment #7
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedLooks good to me, let's see what the bot says...
Comment #9
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedTest on #6 fails with:
So this tells me that the test is indeed correct.
Here is both the fix and the test combined into one, against 8.4.x
Comment #10
keesje CreditAttribution: keesje commentedCool, combined patch applied cleanly.
Thanks!
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedThanks, looks perfect!
At first I wanted to propose bit refactoring, like:
but it did not get much better and is not related to the problem.
Do we need this comment?)
Comment #12
larowlanWe could do this in a one-liner
- not sure it matters though
Can we use the
::class
constants here. It makes discovery of dependencies more explicit, e.g. IDEs will find, but they're less likely to find these strings.Comment #13
larowlanNeeds work for item 2 of #12. Not fussed either way on item 1.
Comment #14
keesje CreditAttribution: keesje commented@lorowlan, thanks for your feedback. I don't see a problem to use ::class constants. but wouldn't that be inconsistent with other tests in the same suite? In my opinion changing that isn't the scope of this issue.
Comment #15
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedI tend to agree with @keesje here... a quick grep across core also shows that this is a very common pattern.
Perhaps tackling this problem on a different issue for all core tests would make sense?
Comment #16
Anonymous (not verified) CreditAttribution: Anonymous commented#13: +1 :)
class
instead ofstring
Comment #17
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedMakes sense @vaplas
It came to mind that @larowlan is now a committer so that settles it then :-D
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedNice idea! This make sense to me regardless of the results here. And I have some experience to do it. But such a global change will be commited around beta-rc phase of 8.4 (i.e. not yet soon).
Comment #19
pk188 CreditAttribution: pk188 at OpenSense Labs commentedSo, fixed 1 of #12 and not 2.
Comment #20
Anonymous (not verified) CreditAttribution: Anonymous commented#19: thanks for help, @pk188. But we can see on the code:
$this->total_items = max(0, $this->total_items);
like on:
And this is no better than:
right?
I think such a view is main reason why @larowlan added next comment
'Not fussed either way on item 1.'
, and why #11 also not an ideal :)And iterdiff between patches is very useful to make sure that no other changes (by chance).
Comment #21
larowlan@pk188 can you please provide an interdiff for #19?
Comment #22
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedHere it is @larowlan
@pk188 you can have a look at how to create these here https://www.drupal.org/documentation/git/interdiff :)
Comment #23
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedOops, wrong file extension (should be .txt) sorry test bot!
Comment #25
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedComment #26
pk188 CreditAttribution: pk188 at OpenSense Labs commentedInterdiff @larowlan. Sorry for being late.
Comment #27
larowlan@pk188 - no need to apologize, thanks for working on this bug.
Can we get the change to use
::class
constants done here too, easier to do it before than later.Can we get this comment added back?
This is very close, thanks everyone for accommodating my feedback.
Comment #28
pk188 CreditAttribution: pk188 at OpenSense Labs commentedFixed #27.
Comment #29
larowlan@pk188 thanks again - please look after your reviewers by providing an interdiff, so they don't have to review everything from scratch :)
These still need to use ::class constants
Comment #30
Anonymous (not verified) CreditAttribution: Anonymous commented#15 done #2886352: Replace string 'path/to/class' with ::class constant :)
This can be used here like hint.
Comment #31
Anonymous (not verified) CreditAttribution: Anonymous commented#27
What additional information will this comment give?) Is not the self-documenting code? And we have a test coverage to prevent remove this change.
$this->total_items = max(0, $this->total_items);
We can move it closer to a place that has a negative effect. For example, if the offset is moved to another location, we can get rid of unnecessary code. And it will be the closest:
$this->total_items = max(0, $all - $offset);
But in any case, this is not the question that really worries me :)
Comment #32
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedYay!
Switching the test to use ::class constants.
Comment #33
larowlanLooks good to me
Comment #35
catchCommitted/pushed to 8.4.x, thanks!