Skip to content

[6.x] Fix “is not one of” in ID-based condition rules and the asset kind param - #20786

Merged
riasvdv merged 6 commits into
6.xfrom
rias/fix-not-condition-rules
Nov 17, 2026
Merged

riasvdv merged 6 commits into
6.xfrom
rias/fix-not-condition-rules

Conversation

@riasvdv

@riasvdv riasvdv commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Condition rules that filter by ID passed their param value straight to query methods that run a plain whereIn(). For “is not one of”, that value is ['not', …ids], so the rule matched only the excluded items. A new BaseMultiSelectConditionRule::paramIds() resolves the value against the rule's table first, the way the queries' own sectionId/typeId/volumeId params do.

 SectionConditionRule::modifyQuery()   // also TypeConditionRule, VolumeConditionRule, AffiliatedSiteConditionRule
-  applySectionId(paramValue())                          // ['not', 1] → sectionId IN ('not', 1)
+  whereIn('entries.sectionId', paramIds(Table::SECTIONS, …))   // ['not', 1] → every other section ID

 SiteGroupConditionRule::modifyQuery()
-  paramValue() → getGroupByUid('not') dropped           // “is not one of” acted as “is one of”
+  paramIds(Table::SITEGROUPS, …) → each group's sites

The asset query's kind param had the same problem with not. Files with the kind's extensions were OR'd back in, so kind('not image') still matched images:

 applyKind('not image')
   kind != 'image'
-  OR filename LIKE '%.jpg' OR …
+  AND filename NOT LIKE '%.jpg' AND …

The extension check also parses the value now, so kind('image, audio') matches files by extension like kind(['image', 'audio']) does.

Also, after review:

  • paramIds() skips soft-deleted rows, so entries in trashed sections don't match “has a value” or “is not one of”.
  • Excluding every entry type or volume matches nothing. applyTypeId() and applyVolumeId() treat [] as no matches, as applySectionId() already did.
  • Affiliated Site “is not one of” filters affiliatedSiteId NOT IN (…) OR IS NULL, so users without an affiliated site match, as they do in matchElement().
  • The Section rule's matchElement() no longer matches sectionless entries, which its query leaves out, like SectionTypeConditionRule.
  • The Section and Section Type rules filter entries.sectionId directly rather than through EntryQuery::applySectionId(), which set the outer query's structureId/withStructure when one section was left. In an “or” condition group, that gave entries matched by other rules the wrong structure ID.
  • kind() with “or” or “and” checks each kind as its own (stored kind OR one of its extensions) group, combined with the param's operator, so kind(['and', 'image']) and kinds that share an extension (.ogg for audio and video) match by extension.

This affects every place an entry, asset, or user condition filters a query, such as custom element sources.

Evidence

  • Before: all of these failed on 6.x.
    After: they pass.
SectionConditionRule “not in [news, blog]”       → expected [pages],   got [news, blog]
TypeConditionRule “not in [type1]”                → expected [entry2],  got [entry1]
VolumeConditionRule “not in [volume1]”            → expected volume2,   got volume1
AffiliatedSiteConditionRule “not in [primary]”    → expected [other],   got [primary]
SiteGroupConditionRule “not in [primary group]”   → expected 0 entries, got 1
assets.kind('image, audio')                       → expected 3, got 2
assets.kind('not image')                          → expected 2, got 3
assets.kind(['not', 'image', 'audio'])            → expected 1, got 4

The review fixes, each failing before its commit:

SectionConditionRule “not in” / “has a value” with trashed section → trashed entry returned
SectionConditionRule::matchElement(sectionless entry, “not in”)    → expected false, got true
TypeConditionRule “not in [every type]”                            → expected [], got both entries
VolumeConditionRule “not in [every volume]”                        → expected 0, got 2
AffiliatedSiteConditionRule “not in [primary]”                     → unaffiliated user missing
assets.kind('and image, audio')                                    → expected 0, got 3
Section / Section Type rule in an “or” group with a channel entry  → channel entry got structureId 1
assets.kind(['and', 'image'])                                      → expected 2, got 1
assets.kind('and audio, video') with file.ogg                     → expected 1, got 0

riasvdv and others added 2 commits November 17, 2026 13:26
The Section, Entry Type, Volume, and Affiliated Site rules passed their
param value, such as ['not', 1, 2], to query methods that run a plain
whereIn(), so “is not one of” matched only the excluded items. The Site
Group rule looked 'not' up as a group UID, dropped it, and matched the
selected groups instead of excluding them.

BaseMultiSelectConditionRule::paramIds() now resolves the param value
against the rule's table, the way the queries' own sectionId, typeId,
and volumeId params do, so these rules pass a list of IDs.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
kind('not image') still matched images, because files with the kind's
extensions were OR'd back in. Those extensions are now excluded too.
The extension check also parses the value, so kind('image, audio')
matches files by extension like kind(['image', 'audio']) does.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved filtering bugs allow excluded records through, reject valid sectionless or unaffiliated records, include entries in deleted sections, and apply OR semantics to AND asset-kind conditions.

6 open issues
What changed in this PR

This PR addresses incorrect “is not one of” filtering in Craft’s element conditions and updates asset-kind queries to handle exclusions and comma-separated values.

Changes:

  • Adds shared ID resolution for section, entry-type, volume, affiliated-site, and site-group conditions.
  • Updates asset-kind extension checks to respect negation.
  • Adds regression coverage for negative conditions and asset-kind parameters.
File Description
tests/​Feature/​User/​Conditions/​UserConditionRulesTest.php Adds affiliated-site exclusion coverage.
tests/​Feature/​Entry/​Conditions/​EntryConditionRulesTest.php Expands section and entry-type filtering coverage.
tests/​Feature/​Element/​Queries/​Concerns/​Asset/​QueriesAssetPropertiesTest.php Covers comma-separated and negated asset kinds.
tests/​Feature/​Element/​Conditions/​ElementConditionRulesTest.php Adds site-group exclusion coverage.
tests/​Feature/​Asset/​Conditions/​AssetConditionRulesTest.php Adds volume exclusion coverage.
src/​User/​Conditions/​AffiliatedSiteConditionRule.php Resolves site conditions into IDs before filtering.
src/​Entry/​Conditions/​TypeConditionRule.php Uses resolved entry-type IDs.
src/​Entry/​Conditions/​SectionConditionRule.php Uses shared section-ID resolution.
src/​Element/​Queries/​Concerns/​Asset/​QueriesAssetProperties.php Parses kind parameters and negates extension checks.
src/​Element/​Conditions/​SiteGroupConditionRule.php Resolves group IDs before collecting sites.
src/​Condition/​BaseMultiSelectConditionRule.php Adds the shared paramIds() resolver.
src/​Asset/​Conditions/​VolumeConditionRule.php Uses resolved volume IDs.

Review effort: Balanced

riasvdv and others added 2 commits November 17, 2026 13:58
…rules

- paramIds() skips soft-deleted rows, so “has a value” and “is not one
  of” no longer match entries in trashed sections.
- Excluding every entry type or volume now matches nothing, rather than
  resolving to an empty ID list that applyTypeId() and applyVolumeId()
  ignored.
- “Is not one of” on the Affiliated Site rule now matches users without
  an affiliated site, as matchElement() already did.
- The Section rule's matchElement() no longer matches sectionless
  entries, which its query leaves out.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
Co-authored-by: Amp <amp@ampcode.com>
A file has only one kind, so kind('and image, audio') can't match any
file. The extension check used to OR in every listed kind's extensions.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
Co-authored-by: Amp <amp@ampcode.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Negated section filters can incorrectly alter outer-query structure settings and hierarchy data, while AND kind filters can omit assets that match by filename extension.

2 open issues
6 resolved since last review

Review effort: Balanced

The Section and Section Type rules used EntryQuery::applySectionId(),
which sets the outer query's structureId or withStructure when one
section is left. In an “or” condition group, entries that another rule
matched then got the wrong structure ID or lost their structure data.
The rules now filter entries.sectionId directly.

kind() with “or” or “and” now checks each kind as its own group of
“stored kind, or one of its extensions”, combined with the param's
operator. kind(['and', 'image']) matches files by extension again, and
kinds that share an extension, such as audio and video with .ogg, can
both match one file.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
Co-authored-by: Amp <amp@ampcode.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The kind filter reparses decoded scalar values, splitting literal commas and potentially missing intended assets or matching unrelated ones.

1 open issue
2 resolved since last review

Review effort: Balanced

The kind param is already parsed into values, so passing each one to
whereParam() as a string parsed it again. kind('drawing\,cad') was split
into “drawing” and “cad”, and a kind named like an operator would have
been read as one.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
Co-authored-by: Amp <amp@ampcode.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because unscoped structure joins can duplicate entries with different hierarchy data and consume extra pagination slots.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@riasvdv
riasvdv requested a review from brandonkelly November 17, 2026 14:48
@riasvdv
riasvdv merged commit 00f0859 into 6.x Nov 17, 2026
23 of 24 checks passed
@riasvdv
riasvdv deleted the rias/fix-not-condition-rules branch November 17, 2026 14:49
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.

3 participants