silverstripe / silverstripe-sqlite3

SQLite3 DB Adapter for Silverstripe
BSD 3-Clause "New" or "Revised" License
8 stars 19 forks source link

Iterator loop over the same item twice #73

Open lekoala opened 10 months ago

lekoala commented 10 months ago

Just found a really odd issue when testing sqlite

in a template i have this

<% loop MyList %> ... <% end_loop %>

The list contains only one record, but it's displayed twice

It seems due to the switch to generators We have yield $data, but that is actually called twice due to the rewind call in SSViewer_scope. I don't have a solution yet. Removing $this->itemIterator->rewind(); fixes the issue, but it's probably there for a reason.

Also, with sqlite, fetchArray can start giving AGAIN the results after false has been returned, so that might also be it, or a combination of both issues.

PRs

lekoala commented 10 months ago

so i think i got the general idea. The issue happens here

https://github.com/silverstripe/silverstripe-framework/blob/64e2b5e48981d68487a5be34b287018dcd6a482a/src/View/SSViewer_Scope.php#L303-L313

https://github.com/silverstripe/silverstripe-framework/blob/64e2b5e48981d68487a5be34b287018dcd6a482a/src/ORM/DataList.php#L1502-L1509

working on a fix :)

lekoala commented 10 months ago

so i have a solution not sure it's the best one, but at least it's working :)

GuySartorelli commented 8 months ago

This will need to wait until https://github.com/actions/runner-images/issues/9033 is resolved so we can use a compatible version of sqlite3 in CI

lekoala commented 8 months ago

@GuySartorelli well, the ci is not needed to confirm that my fix works :-) but i'm in no rush, no issues with running my own little fork in the meantime