Cms: Querying by lightswitch value stopped working

Created on 4 Oct 2019  路  5Comments  路  Source: craftcms/cms

Description

Querying an entry by a lightswitch value stopped working for both true and false values.

Steps to reproduce

  1. Query entries by a lightswitch value. e.g. craft.entries.section('pages').isFeatured(true)
  2. Resultset contains all possible results (both isFeatured=true, and isFeatured=false) as the generated query is AND (NOT ("content"."field_isFeatured" IS NULL))

Additional info

  • Craft version: 3.3.6
  • PHP version: 7.3.10
  • Database driver & version: PostgreSQL 11.5

Most helpful comment

Just fixed this for the next release. We鈥檒l get that out ASAP, but if you need it right away, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#600e937048d83dc2ae6498a348b9f47aab064f35 as 3.3.7",
  "...": "..."
}

Then run composer update.

All 5 comments

What happens when you query using:

craft.entries.section('pages').isFeatured('not 1')
craft.entries.section('pages').isFeatured('0')

Same result for 1, '1', true/false, 'not 1' etc. @jonleverrier

Edit: Weird, this worked before in 3.3.6 but after updating to 3.3.7, and reverting back to 3.3.6, did not solve the issue. See below.

I've verified this is happening only when using Postgres.

Last tested working version is 3.3.3, version 3.3.4 had the same issue as MySQL which was fixed in 3.3.4.1, but from there on Postgres queries are unable to search by lightswitch at all.

Hope this can be fixed in the next release. Downgrading to 3.3.3 is a solution until that time.

Can confirm this is the case. This seems to be related to recent changes in how lightswitch works by @brandonkelly

Just fixed this for the next release. We鈥檒l get that out ASAP, but if you need it right away, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#600e937048d83dc2ae6498a348b9f47aab064f35 as 3.3.7",
  "...": "..."
}

Then run composer update.

Was this page helpful?
0 / 5 - 0 ratings