Closed k7y6t5 closed 2 years ago
Thanks for pointing that out. It is intended that user queries don’t apply a status by default in Craft 4; the docs were just not updated accordingly. The docs will fix themselves after the next release gets tagged.
Ok thanks @brandonkelly. One follow-up though. {% set people = craft.users.status('active').all() %}
returns both active
and suspended
users. Is that intended?
Yeah that’s expected. active
just means that they have the means to log in (they either have a password already, or they could create/recover a password from a lost-password workflow.
Realized there was an undocumented change in behavior here, and the consensus internally is that we should retain the old behavior where active
doesn’t include suspended users. So that has been reverted for the next release.
Huzzah! Thank you 🎉
Craft 4.0.4 is out now with that change ✨
What happened?
Description
When updating from Craft 3 to 4, user queries are not correctly filtering by status.
According to the docs,
active
is the default. https://docs.craftcms.com/api/v4/craft-elements-db-userquery.html#method-statusSteps to reproduce
Scenario A:
{% set people = craft.users.all() %}
Scenario B:{% set people = craft.users.status('active').all() %}
Expected behavior
Scenario A: The table should contain only users with status
active
(based onactive
being the default). Scenario B: The table should contain only users with statusactive
.Actual behavior
Scenario A: The table contains users with any of the statuses
active
,inactive
,suspended
,pending
. Scenario B: The table contains users with statusactive
and users with statussuspended
.Craft CMS version
4.0.3
PHP version
8.0.19
Operating system and version
Ubuntu 20.04.4 LTS
Database type and version
MySQL 8.0.29
Image driver and version
Imagick 3.7.0 (ImageMagick 6.9.10-23)
Installed plugins and versions
Asset Usage 3.0.0-beta.1 Cookies 4.0.0 Feed Me 5.0.4 Redactor 3.0.0
Super Table 3.0.0-beta.4