Closed (cannot reproduce)
Project:
Pathauto
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
25 Jan 2018 at 12:24 UTC
Updated:
13 Feb 2026 at 16:22 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tuutti commentedComment #3
berdirwhat entity type is this?
The path field is expected to be computed and auto-loaded, it should always have a field item, even when there is no alias.
Comment #4
tuutti commentedWe populate a bunch of entities during Behat test that will be automatically deleted after every step. Everything else except nodes and taxonomy terms seems to work just fine.
I've tried to reproduce this without behat, but with no success.
Comment #5
berdirwhich drupal core version? 8.4?
I'll have a closer look at this asap. We should be doing some updates now that path is a able to load itself anyway I think, might also help wit hthis.
Comment #6
tuutti commented8.4
Comment #7
berdirThere were various reports since 8.4 about strange effects. Only found time now to start looking into it. Can you check if #2945734: Fix automated test failures in 8.x-1.x is fixing this for you?
If not, a failing test would be helpful.
Comment #8
tuutti commented#2945734: Fix automated test failures in 8.x-1.x seems to fix this as well. Thanks!
Comment #9
tuutti commentedLooks like #2945734: Fix automated test failures in 8.x-1.x didn't fix this after all.
Repository to demonstrate the issue: https://github.com/tuutti/pathauto_2939432_demo
Failing test: https://travis-ci.org/tuutti/pathauto_2939432_demo/builds/369355510
Comment #10
tuutti commentedAlso, here's the patch we're using for now.
Comment #11
tuutti commentedComment #12
tuutti commentedI dug a bit deeper into this and this seems to break only if you create a new entity and save it before adding a new translation.
For example, this works just fine:
but this doesn't:
Comment #14
tuutti commentedComment #15
berdirPlease provide a combined patch as well to show that it passes then.
Needs description for the class and $modules property.
why the conditional, this isn't called multiple times?
$entityType should be $entity_type.
this also seems unused?
there is nothing in this test that requires it to be a browser test, it should be a kernel test instead.
One test method is also enough, and once it is fixed, it doesn't make sense to talk about working and non-working as both are working. Instead, name it after what it is testing/doing (testDeleteTranslations() or something like that)
you don't really need a helper function for this, just do it inline and remove the body part, because that field doesn't exist in this test.
Comment #16
tuutti commentedI just put something together to test if this was somehow PHP version related, sorry.
Comment #18
tuutti commentedHmm, looks like #2950701: Pathauto pattern is not applied on first node save. might have fixed this as well.
Comment #19
tuutti commentedComment #20
berdirGood, but more test coverage never hurts, maybe that revert was temporary and then we want to make sure that it doesn't break again, so keeping open as a task to add that, which possibly is the test-only patch that you provided above..
Comment #21
benjy commentedRe-roll of #16 but moved the logic into the module file as we no longer implement delete in the field item list? Also brought back the functional test from #14.
Comment #22
jhedstromI'm seeing this behavior in pathauto 1.3 when combined with
weitzman/drupal-test-traits. The automatic cleanup happens during phpunit'stearDownphase. It only happens occasionally (still don't know exactly what causes it, but it's certain user entities).Comment #23
jwjoshuawalker commentedI'm using Drupal in a headless manner (and all content is created via Entity Interfaces), I have to use this patch #21 to avoid issues.
Though, it hasn't cleanly applied to
1.x-devfor a month+ now, so I've held back at previous pathauto version.Just chiming in to possibly help discover how/when/why this happens. (Non-UI created content?)
Comment #24
jwjoshuawalker commentedPatch no longer applies to latest dev.
Comment #25
sokru commentedJust a reroll from #21
Comment #26
jwjoshuawalker commentedNice! I'll try to test this tomorrow.
Comment #27
zenimagine commentedHi, will the patch be applied to the next version ?
Comment #28
berdirThis isn't a very descriptive class name, maybe EntityDeleteTest or so?
was this method copied from somewhere?
we only call it once, maybe just inline it into setUp()? then we don't need the dynamic language installed flag and also not the.
And are we sure that rebuild is actually needed?
Also looks like this could be a much faster kernel test, we don't do any web requests here?
working and broken aren't really useful method descriptions, because it wouldn't actually be broken anymore?
Just one method that tests the broken part would I think also be enough.-
Comment #29
sv commentedHi, after applying a patch still have an issue, so I've improved it a bit.
Comment #30
raman.b commentedAddressing the pointers from #28 and including the improvement from #29
Comment #31
raman.b commented🤔
Comment #33
raman.b commentedComment #36
mably commented"Test-only changes" doesn't fail. So not sure all this is really needed.
Comment #37
mably commentedCode review of MR #129
The commit adds a null check in
PathautoEntityHooks::entityDelete()before calling->get('pathauto')->purge(). The original code called$entity->get('path')->first()->get('pathauto')->purge()without verifying thatfirst()returns a valid item, which could cause a fatal error: "Call to a member function get() on null".The fix stores
$entity->get('path')->first()in a variable and checks$item instanceof PathautoItem && $item->__isset('pathauto')before proceeding. This is a correct defensive measure.Test investigation
The test included in the MR (
EntityDeleteTest) had several issues:pathmodule in$modules, and did not install thenodeandpath_aliasentity schemas or pathauto config. As a result, the path field was not available on the node entity and the delete hook'shasField('path')check returned FALSE — the test never actually exercised the fix.#[RunTestsInSeparateProcesses]attribute required since Drupal 11.3.ComputedItemListTrait::get()always callsensureComputedValue(), sofirst()returns a valid item.After fixing the test setup, the only way to make
first()return NULL is to artificially clear the path field with$node->get('path')->setValue([])before deletion. This marks the computed value as already resolved while emptying the item list. With this approach, the test correctly crashes without the fix ("Call to a member function get() on null") and passes with it — but it does not correspond to a real-world use case.Conclusion
The fix itself is correct and harmless as a defensive null check. However, the original bug may no longer be reproducible in Drupal 11 due to changes in
ComputedItemListTrait. The test can only verify the fix by artificially creating the null condition.Comment #38
mably commentedFeel free to reopen this issue if you can provide a reproducible scenario on a fresh Drupal instance.