Scenario collection endpoint leaks embedded buckets (N+1 + contract violation) #68
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug
GET /api/scenarios(the collection) embeds each scenario'sbucketsarray, when only the item representation (GET /api/scenarios/{id}, #64) should. This is both a contract violation (the lean list shape documented onScenario::$buckets) and an N+1: every scenario lazy-loads its bucket collection on every list request.Root cause
GetCollection()onScenario(src/Entity/Scenario.php) has nonormalizationContext. In API Platform, an operation without a normalization group context serializes all readable properties, ignoring the#[Groups]annotations entirely (groups only filter when the context names which groups to use). Sobuckets— groupedscenario:read, intended item-only — leaks into the collection.How it went unnoticed
The guard test
App\Tests\Functional\ScenarioApiTest::testGetCollectionDoesNotEmbedBuckets(added in #64,6fd2243) has been failing since it was written — confirmed by running it against the #64 version of the entity: it fails identically. The full backend suite evidently wasn't run clean since #64 (the container-dev tooling was broken; tests ran ad-hoc). Surfaced during #54's finish-phase full-suite run: 260 tests, this 1 failure.Fix
Give
GetCollectionan explicit leannormalizationContext(ascenario:summarygroup coveringname+descriptiononly), sobucketsstays confined to the item op'sscenario:read. The item op's context must include the summary group too soname/descriptionstill serialize there.normalizationContext: ['groups' => ['scenario:summary']]['groups' => ['scenario:summary', 'scenario:read', 'bucket:read']]name/description: addscenario:summary(keep readable on both);buckets: staysscenario:readonly.Testing
testGetCollectionDoesNotEmbedBucketsgoes green (the guard).testGetItemEmbedsItsBuckets+ the item field tests stay green (item still embeds).Notes
cache:clearfor API Platform metadata.