Newly-added readable property on an existing resource is silently dropped from the (JSON-LD) output until var/cache is deleted; cache:clear does not invalidate it
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- php, symfony
- Ambito
- api, backend, backend-api-design
Direzione di ricerca
Parti da AbstractItemNormalizer::getAllowedAttributes(), quindi segui PropertyNameCollectionFactoryInterface::create() fino a api_platform.cache.metadata.property e al debug cache warmer. Riproduci il problema mettendo in cache una risorsa esistente, aggiungendo una proprietà leggibile e confrontando cache:clear con l’eliminazione di var/cache; il lavoro è completato quando la proprietà viene serializzata dopo l’invalidazione della cache senza rimuovere manualmente var/cache.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
After adding a readable property to an already-cached API resource class, the serialized
output (tested with application/ld+json) omits that property — no error, the key is simply
absent — even though the property is readable: true, has a value set, and shows up in the
OpenAPI/Hydra schema. Deleting var/cache/<env> fixes it; bin/console cache:clear and
cache:pool:clear do not.
The metadata is correct when computed fresh. The drop happens because the serializer reads a
stale PropertyNameCollection out of api_platform.cache.metadata.property.
Environment
- Symfony 7.x, PHP 8.5, debug enabled (dev and test reproduce identically).
- Note (transparency): the install where this was found is version-skewed —
api-platform/metadata+api-platform/json-schemaat4.3.13, the rest
(serializer,jsonld,hydra,state,symfony, …) at4.3.10. I was not able to fully
rule the skew out as a contributing factor, but the mechanism below is version-independent.
Reproduction
- A custom (non-Doctrine) resource backed by a state provider, e.g. a DTO with
#[ApiProperty(writable: false)] public int $foo = 0;set by the provider. Hit the item GET
once so the metadata is cached. - Add another
readableproperty to the same existing class
(#[ApiProperty(writable: false)] public int $bar = 0;), set it in the provider/fromEntity. - Hit the item GET again.
Expected: bar present. Actual: bar absent, no error.
rm -rf var/cache/<env> → bar appears. bin/console cache:clear (or
cache:pool:clear cache.system) → bar still absent.
Where the drop happens (traced)
PropertyNameCollectionFactoryInterface::create()/PropertyMetadataFactoryInterface::create()
called directly return the full, fresh set:barpresent,readable=true, native type
resolved. Metadata layer is fine.AbstractItemNormalizer::getAllowedAttributes()→
$this->propertyNameCollectionFactory->create($resourceClass, $options)returns a stale
list that does not includebar. So the new readable property never reaches the attribute set;
it is dropped with no error. (getFactoryOptions()builds slightly different options than a
hand call, but the relevant difference is just that the serializer's call hits a cached entry.)
Mechanism
api_platform.cache.metadata.propertyis defined->parent('cache.system')(aPhpFilesAdapter
undervar/cache/<env>/pools/system/<ns>/). Its items are versioned bycontainer.build_id
(AbstractAdapter::createSystemCache('<ns>', 0, $container->getParameter('container.build_id'), …)).- The cached
PropertyNameCollectionkey is derived from resource class + options — it carries
no source-version component. So once the collection for a class is cached, a body edit to
that class (adding a property) does not change the key, and the cached value keeps being served. api_platform.cache_warmer.cache_pool_clearer(registered only in debug) is supposed to clear
these pools on warmup, yet in practicecache:cleardoes not invalidate the entry the running
app/worker reads — only physically deletingvar/cachedoes. (I could not make the
container.build_id/ pool-namespace / rebuild-timing interaction deterministic enough to say
exactly why the clearer misses; that part may be Symfony cache.system plumbing rather than core.)
Impact
- Under a long-lived worker (FrankenPHP/Symfony runtime) it is worse: metadata is read once at
boot and a restart re-reads the same stale persistent pool.var/cachemust be wiped before the
restart.
Notes
Adding a new resource class (which changes the compiled container) is picked up fine; the bug
is specifically editing the property set of an existing, already-cached resource. Happy to
build a minimal reproduction app if useful.
- Lingua principale
- PHP
- Stelle
- 2.6k
- Fork
- 982
- Merge medio
- 1g 16h
- PR unite (30g)
- 59
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/core
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
api-platform/core#8573 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
api-platform/core#8571 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
api-platform/core#8564 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
api-platform/core#8495 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
api-platform/core#8471 ·
Tutte le issue di api-platform/core
Issue simili
-
tooling
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
UX
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ProfessionalWiki/NeoWiki#1525 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
OpenConext/OpenConext-engineblock#2122 ·
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Automattic/safe-publish#594 ·