Problem/Motivation
After enabling Memcache as the default Drupal cache backend with transaction-aware mode, newly created content aliases could return 404 immediately after save, even though the alias record existed. The alias usually started working after cache rebuild, which indicates a timing/caching side effect rather than missing alias generation.
What was happening:
1. Environment used transaction-aware Memcache as default cache backend.
2. In Pathauto 1.15 flow, alias link rendering for status messages happened too early in the save lifecycle.
3. That early URL resolution could interact badly with routing/path alias cache state during write operations.
4. Result: first request to the fresh alias could be cached/resolved incorrectly, giving a false 404 until cache invalidation.
Steps to reproduce
1. Configure Drupal with Memcache enabled and set default backend to:
$settings['cache']['default'] = 'cache.backend.memcache_transaction_aware';
2. Ensure Pathauto 1.15 is installed.
3. Clear caches once before test.
4. Create a new published node with a generated alias.
5. Immediately request the generated alias URL.
6. Observe intermittent or consistent 404 on first access.
7. Run cache rebuild.
8. Request same alias again.
9. Observe alias resolves (200), confirming cache/state timing issue.
Optional validation signal:
1. Canonical system path can work while alias fails initially.
2. Alias recovery after cache rebuild strongly suggests stale/early route/alias resolution side effect.
Proposed resolution
Implement a low-risk behavioral fix in Pathauto alias save messaging flow:
1. Defer alias link generation until after alias entity save completes.
2. Keep message behavior intact (still outputs clickable alias when possible).
3. Add safe fallback so message rendering cannot break alias flow if URL generation fails.
Implementation summary:
1. In the save path, call alias entity save first.
2. Only then generate message link from the persisted alias.
3. Wrap link formatting with try/catch and return plain alias text on failure.
Why this is safe:
1. No change to alias generation rules.
2. No change to update/create decision logic.
3. No schema/config change.
4. Fix is isolated to message-time URL rendering order.
Remaining tasks
1. Convert local contrib modification into a Composer patch file under patches/pathauto.
2. Register patch in composer.json patch section for drupal/pathauto.
User interface changes
1. No visual UI layout changes.
2. Status message content remains effectively the same to users.
API changes
1. No public API contract changes.
2. No new routes, services, plugin definitions, or hooks.
Data model changes
1. No Data model changes.
Issue fork pathauto-3608478
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
kmaniComment #4
rozzi commentedI don't think we use memcache, but I faced the same issue and didn't know how to reproduce it on a fresh install. Applying the diff as a composer patch solves the problem. If only I knew to look here before the two full days spent attempting to troubleshoot!
Comment #5
agoradesign commentedI've had the same problem, and the patch fixed it for me.
Under certain circumstances, I've even got an Internal Server error (because of "TypeError: Drupal\\Core\\Database\\StatementWrapperIterator::__construct(): Argument #2 ($clientConnection) must be of type object, null given, called in /app/web/core/lib/Drupal/Core/Database/Connection.php on line 441"). This one was also well reproducible before applying the patch. Now it seems to work :)