craftcms / craftcms/element-api
`postDate` is not respected as cache TTL
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 502
- Forks
- 55
- PR merge metrics
- No merged PRs in 30d
Description
Description
When an Entry has a postDate in the future (pending) the \craft\base\Element::@$enabledForSite is disabled.
Once the postDate is in the past this (and other fields) becomes enabled, but the API will still return the old disabled value. Adding a random cache-busting query parameter to the API call will return the correct new state.
We use Craft as a headless CMS and want to be able to schedule articles in the future. However the cache isn't expired when the postDate is in the past.
Steps to reproduce
- Create an Entry that will be published in the future
- Request the Entry via the API with the criteria
statusset to[Entry::STATUS_LIVE, Entry::STATUS_PENDING] - Observe the
enabledForSitestate being false - Wait for the Entry to become public
- Refetch the data via the API
- The
enabledForSiteis still reported as false - Of course all other data is also stale; the status etc etc
Additional info
- Craft version: 4.8.1
- PHP version: 8.1
- Database driver & version: mysql 5.7
- Plugins & versions: Element API 3.0.1.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Element API request path for Entry queries using the live and pending status criteria, then trace how response caching handles an Entry's postDate. Reproduce the seven-step scenario with Craft 4.8.1 and confirm that the API returns updated enabledForSite and status data when the Entry becomes public.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100