Skip to content

[6.x] Cache term augmentation with taxonomy-qualified ID - #15974

Merged
jasonvarga merged 3 commits into
statamic:6.xfrom
Boefjim:bugfix/cache-term-augment-with-taxonomy
Nov 19, 2026
Merged

jasonvarga merged 3 commits into
statamic:6.xfrom
Boefjim:bugfix/cache-term-augment-with-taxonomy

Conversation

@Boefjim

@Boefjim Boefjim commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

When using a single-taxonomy field in a blueprint, the augmented value is cached based purely on the slug, since the taxonomy is left out of the value in these cases.
If two of these fields exist and each cover different taxonomies but happen to have the same slug across them, the second augmentation will read the value of first augmentation, causing a term from a different taxonomy to be read.
This can break whatever is being shown quite badly (I have ran into this issue on a Statamic project myself).

With this change, the taxonomy-qualified IDs will be used in the cache key to ensure it will only cache values from within the taxonomy that the terms are from.

@jasonvarga
jasonvarga merged commit 92d484b into statamic:6.x Nov 19, 2026
61 checks passed
bpmore pushed a commit to UAMS-Web/uams-statamic that referenced this pull request Nov 26, 2026
… term (#1565)

Closes #1517.

An assessment-based certificate's Certification JSON-LD again leaves out
its audit and expiration dates on `statamic/cms` 6.43.1. The schema
context now augments a term stored under a handle shared by two
replicator sets through the set whose taxonomy holds the term, rather
than the first single-item field.

## The bug

Two replicator sets on `people` store a term under `activity`: a degree
row (`taxonomies: [credentials]`) and a certification row (`taxonomies:
[certifications]`). `selectTermsLikeBlueprintFieldForMergedValue()`
chose between same-handle fields by storage shape only, so a
certification slug was augmented through the degree row's field, as a
`credentials` term. Probed on 6.43.1: the certificate slug augmented
with the `credentials` field config and returned `null`, which
`CertificationRowKind::termKind()` then received as an empty collection.

## The `statamic/cms` change that exposed it

statamic/cms#15974 (commit `92d484b83`, first tagged in **v6.43.0**),
"Cache term augmentation with taxonomy-qualified ID", in
`src/Fieldtypes/Terms.php`:

- v6.40.0, line 161: `Blink::has($key =
'terms-augment-'.$site.'-'.json_encode($values))`, keyed by the bare
slug.
- v6.43.1 and v6.44.0, line 165: `$key =
'terms-augment-'.$site.'-'.json_encode($this->convertAugmentationValuesToIds($values));`,
keyed by `taxonomy::slug`.

Under the bare-slug key, the wrong-field augment hit the term an earlier
augment through the right field had cached, so the wrong choice was
invisible. Under the qualified key it misses, queries
`credentials::<slug>`, and finds nothing. Confirmed on 6.43.1 by putting
v6.40.0's key line back into
`vendor/statamic/cms/src/Fieldtypes/Terms.php` with no site change: both
tests passed (10 of 10), and failed again with the vendor file restored.
`git diff v6.43.1 v6.44.0` is empty for `src/Fieldtypes/Terms.php`,
`src/Stache/Query/TermQueryBuilder.php`, `src/Fields/Value.php` and
`src/Taxonomies/`.

## Approach

-
[`app/Services/SchemaTemplates/SchemaOutputService.php`](https://github.com/UAMS-Web/uams-statamic/blob/1517-certification-term-overlay/app/Services/SchemaTemplates/SchemaOutputService.php):
new `termsLikeCandidatesHoldingStoredTerm()` keeps, when there are two
or more candidates and the stored value is a slug or qualified id (bare,
in a `Value`, or first of a list), the candidates whose configured
taxonomies hold that term (`Term::find("<taxonomy>::<slug>")`). A
qualified id only matches its own taxonomy. A value that is already a
term, or that no candidate holds, keeps every candidate, so the
shape-based choice is unchanged there.
-
[`tests/Feature/Services/SchemaTemplates/SchemaOutputServiceTermsLikeTest.php`](https://github.com/UAMS-Web/uams-statamic/blob/1517-certification-term-overlay/tests/Feature/Services/SchemaTemplates/SchemaOutputServiceTermsLikeTest.php):
an eight-row dataset for the degree/certification `activity` pair. The
two field doubles there and in
[`SchemaOutputServiceGuardsTest.php`](https://github.com/UAMS-Web/uams-statamic/blob/1517-certification-term-overlay/tests/Feature/Services/SchemaTemplates/SchemaOutputServiceGuardsTest.php)
now answer `get('taxonomies')`.

No `composer.json` or `composer.lock` change.

## Verification

Measured on Windows 11, PHP 8.4, in a worktree of this branch at
`047f47862`.

| `statamic/cms` | Lock used | `CertificationSchemaDatesJsonLdTest` +
`CertificationNodeCountJsonLdTest` |
| --- | --- | --- |
| 6.40.0 | `main` | without the fix: 10 passed; with it: 10 passed |
| 6.43.1 | #1563's branch, installed for the measurement and not
committed | without the fix: 2 failed, 8 passed (the two named in
#1517); with it: 10 passed |
| 6.44.0 | none available | **not measured** (no branch locks it, and
moving the lock is outside this ticket); the four upstream paths above
are unchanged from 6.43.1 |

- The new dataset is version-independent: with the narrowing disabled
(`return $candidates;`), the five rows expecting the certification field
fail and the three expecting the degree field pass; restored, 8 of 8
pass.
- `SchemaOutputServiceTermsLikeTest` and
`SchemaOutputServiceGuardsTest`: 285 passed.
- Every `tests/Feature/Certification*Test.php` and
`tests/Feature/Services/SchemaTemplates/SchemaOutputService*Test.php`
file (23 files) on 6.40.0, with `vendor/bin/pest`: 778 passed, 8 risky,
0 failed. The two edited test files report no risky test when run alone.
- Pint, PHPStan (`composer stan`, no errors), Rector dry run on the
changed `app/` file, cspell on the three files,
`check-mutate-ignore-breadth` and `check-parallel-safe-tests` pass.

## Companion PRs

- #1563 (#1250, the move to 6.43.1) is red on these two tests and waits
on this one. Merge this first; #1563 then needs `main` merged in.

## Test plan

- [x] Both tests pass on 6.40.0 and on 6.43.1 with the fix, and fail on
6.43.1 without it.
- [x] The selection dataset fails with the narrowing disabled.
- [ ] Local CI green (`node scripts/ci-local.mjs --branch
1517-certification-term-overlay`).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants