craftcms / craftcms/cms

[5.x]: URL lags behind generated fields

Open
#18,061 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

I'm seeing a bug where using a generated field in the URL format of a section causes to URL to 'lag behind' the generated field, i.e. always use the previous value of the generated field instead of the current value.

Steps to reproduce
  1. In an entry type, create a generated field custom with the template set to mirror any text field, e.g.: {my_plaintext_field|slug|lower}
  2. In a section that uses this entry type, set the entry URI format to this custom field: {custom}
  3. Create an entry and save it, then change the value in the text field and save again.
Expected behavior

Whenever the entry is saved, the URL should reflect the new value of the generated field, matching the value of the text field it is based on.

Actual behavior

The URL contains the previous value of the generated field.

Looks like generated fields and URL need to be evaluated in a different order?

Craft CMS version

5.8.18

PHP version

8.3

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with a generated custom field mirrored from a text field and used as the section entry URI format. Trace the entry-save flow to compare when generated fields and URLs are evaluated; done means a second save updates the URL to the generated field's current value.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.