silverstripe-framework: DataList::exists() not working correctly

Affected Version

Silverstripe 4.7 nginx 1.18.0 MariaDB 10.5.5 PHP 7.4.13

installed modules: axllent/silverstripe-image-optimiser axllent/silverstripe-scaled-uploads betterbrief/silverstripe-googlemapfield bummzack/silverstripe-emogrify bummzack/sortablefile dnadesign/silverstripe-elemental firebrandhq/silverstripe-phonelink fromholdio/silverstripe-csshelpers fromholdio/silverstripe-dbhtmlanchors fromholdio/silverstripe-elemental-group fromholdio/silverstripe-elemental-inheritablearea fromholdio/silverstripe-elemental-multiarea fromholdio/silverstripe-errorpagesconfig fromholdio/silverstripe-externalurlfield fromholdio/silverstripe-featureimage fromholdio/silverstripe-globalanchors fromholdio/silverstripe-gridfield-limiter fromholdio/silverstripe-grouploginredirect fromholdio/silverstripe-heroic fromholdio/silverstripe-minigridfield fromholdio/silverstripe-paged fromholdio/silverstripe-schedulable fromholdio/silverstripe-simplevideo fromholdio/silverstripe-singular fromholdio/silverstripe-sortable fromholdio/silverstripe-superlinker-ctas fromholdio/silverstripe-superlinker-megamenus fromholdio/silverstripe-superlinker-menus fromholdio/silverstripe-superlinker-redirection fromholdio/silverstripe-superlinker-targets fromholdio/silverstripe-systemlinks fromholdio/silverstripe-urlsegmenter heyday/silverstripe-responsive-images heyday/silverstripe-wkhtml innoweb/silverstripe-breadcrumbs innoweb/silverstripe-bundled-userforms innoweb/silverstripe-cmsstickymenupreference innoweb/silverstripe-default-home innoweb/silverstripe-dms innoweb/silverstripe-email-obfuscator innoweb/silverstripe-enhancedrss innoweb/silverstripe-form-validation innoweb/silverstripe-googleanalytics innoweb/silverstripe-mailchimp-signup innoweb/silverstripe-metacounter innoweb/silverstripe-minify-html innoweb/silverstripe-page-icons innoweb/silverstripe-prefix-requirements innoweb/silverstripe-requirements-resolver innoweb/silverstripe-robots innoweb/silverstripe-sitemap innoweb/silverstripe-social-metadata innoweb/silverstripe-social-profiles innoweb/silverstripe-social-share innoweb/silverstripe-tinymce-clearfloats jonom/focuspoint littlegiant/silverstripe-persistentgridfield nglasl/silverstripe-misdirection sheadawson/silverstripe-rateable silverstripe/blog silverstripe/html5 silverstripe/recipe-cms silverstripe/userforms stevie-mayhew/hasoneedit symbiote-library/silverstripe-spamprotection-honeypot symbiote/silverstripe-gridfieldextensions symbiote/silverstripe-grouped-cms-menu symbiote/silverstripe-multisites toastnz/silverstripe-gridfieldversionedorderablerows unclecheese/display-logic webbuilders-group/silverstripe-cmspreviewpreference wilr/silverstripe-googlesitemaps

Description

Parts of the site I’m working on are not loading, e.g. the menu items list is empty, the list of blog posts is empty. Other parts of the website load fine.

When I change `DataList::exists()’ back to 4.6 behaviour

public function exists()
{
    return $this->count() > 0;
}

everything works fine again.

On my local machine with MariaDB 10.4.11 and PHP 7.4.2 everything works fine.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 28 (28 by maintainers)

Commits related to this issue

Most upvoted comments

what about a SELECT CASE WHEN EXISTS(...) THEN 1 ELSE 0 END?

For anyone stumbling over this:

I had similar issues in other places, but not directly related to exists() (at least I think so).

I was able to fix it by switching from MySQLPDODatabase to MySQLDatabase. see https://github.com/silverstripe/silverstripe-framework/issues/8598 for reference.

Perhaps line 488 of vendor/Silverstripe/framework/src/ORM/DataQuery.php should be changed from this:

return $result === true || $result === 1 || $result === 't';

to this:

return $result === true || $result === 1 || $result === '1' || $result === 't';

So I’m not crazy. Thanks for confirming. šŸ˜‰