Skip to content

Fixed accidental deletion of referenced cached rows when emptyResultSet is called#207

Merged
dg merged 3 commits into
nette:masterfrom
MartinMystikJonas:bug187
Oct 1, 2018
Merged

Fixed accidental deletion of referenced cached rows when emptyResultSet is called#207
dg merged 3 commits into
nette:masterfrom
MartinMystikJonas:bug187

Conversation

@MartinMystikJonas

Copy link
Copy Markdown
Contributor

Fixed cause of #187

@dg

dg commented Oct 1, 2018

Copy link
Copy Markdown
Member

Wow, thanks!

@dg dg merged commit 6650fbb into nette:master Oct 1, 2018
dg pushed a commit that referenced this pull request Oct 1, 2018
dg pushed a commit that referenced this pull request Oct 1, 2018
dg pushed a commit that referenced this pull request Oct 1, 2018
@MartinMystikJonas

MartinMystikJonas commented Oct 1, 2018

Copy link
Copy Markdown
Contributor Author

@Unlink This fix causes test deleteCahceBug to fail on sqlsrv. But I'm not sure what exactly is tested on line 61 where exception 'Nette\InvalidStateException: Database refetch failed; row with signature '4' does not exist!' is thrown. Could you please explain if it is problem?

@MartinMystikJonas

Copy link
Copy Markdown
Contributor Author

@Unlink Nevermind. It failed even before this change.

@JanTvrdik

Copy link
Copy Markdown
Contributor

@MartinMystikJonas May I ask how does the fix work? Why assigning null by reference is different to assigning null directly?

@f3l1x

f3l1x commented Oct 3, 2018

Copy link
Copy Markdown
Member

Yep, I'm interested too.

@MartinMystikJonas

MartinMystikJonas commented Oct 14, 2018

Copy link
Copy Markdown
Contributor Author

@JanTvrdik @f3l1x

@MartinMystikJonas May I ask how does the fix work? Why assigning null by reference is different to assigning null directly?

$cachedRows = [1,2,3];
$rows = &$cachedRows;
$rows = null;
// $rows = null
// $cachedRows = null

vs

$cachedRows = [1,2,3];
$rows = &$cachedRows;
$null = null;
$rows = &$null;
// $rows = null
// $cachedRows = [1,2,3]

When $rows value is reference to cache and null is assigned then referenced data in cache are corrupted. Assigning new reference moves reference to different location and left cached data intact.

Rows have assigned value by reference from cache here:

$this->rows = &$referencing[$hash]['rows'];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants