Skip to content
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

Fix a bug where Piwik returns wrong rows by label #10947

Merged
merged 3 commits into from Dec 3, 2016
Merged

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Dec 2, 2016

I have just spent a couple of hours remote debugging a bug that I couldn't reproduce. Imaging you limit a data table and remove some rows.

Later you call $table->getRowFromLabel('foobar'); then it might still have the id mapped in $this->rowsIndexByLabel even though the actual column was removed. Ideally, when a row is deleted, we would also delete the map from $this->rowsIndexByLabel directly. Naturally you would think a $table->setLabelsHaveChanged()would fix this but I noticed it does actually not unset all previously stored links so under circumstances $table->getRowFromLabel('foobar'); might actually return a row with a completely different label. This is especially problematic when eg trying to rename something like Archiver::LABEL_NOT_DEFINED. In this case a completely different row was renamed to "Not defined"

This could actually explain a couple of odd issues and may be worth merging into Piwik 2 as well.

@tsteur tsteur added the Needs Review PRs that need a code review label Dec 2, 2016
@tsteur tsteur added this to the 3.0.0-b5 milestone Dec 2, 2016
}

$table->setRows(array($rows[2], $rows[3], $rows[4]));
$table->rebuildIndex();// rebuildindex would be called anyway but we force rebuilding the index just to make sure
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the fix the rows index by label index would have looked like this

array (
'abc' => 0,
'def' => 1,
'ghi' => 0,
'jkl' => 1,
'mno' => 2,
),

@tsteur tsteur merged commit 29e9ed9 into 3.x-dev Dec 3, 2016
@tsteur tsteur deleted the datatablerowlabelfix branch December 3, 2016 20:51
@mattab
Copy link
Member

mattab commented Dec 4, 2016

That's an excellent & tricky find 🎱

@mattab mattab added the Bug For errors / faults / flaws / inconsistencies etc. label Dec 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants