Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce:
- clean D8 english install, standard profile, on today's HEAD
- node/add/article, give it a title, save it
- click to delete it (go to node/1/delete): click on delete on the confirm form
- get an PHP error because the code tries to enumerate fields on a NULL in the id() method
( ! ) Fatal error: Call to a member function id() on a non-object in /(hidden)/core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php on line 73 | ||||
---|---|---|---|---|
Call Stack | ||||
# | Time | Memory | Function | Location |
1 | 0.0001 | 660768 | {main}( ) | ../index.php:0 |
2 | 0.0014 | 953416 | drupal_handle_request( ) | ../index.php:15 |
3 | 0.0243 | 3658736 | Drupal\Core\DrupalKernel->handle( ) | ../bootstrap.inc:1862 |
4 | 0.0250 | 3761008 | Drupal\Core\HttpKernel->handle( ) | ../DrupalKernel.php:281 |
5 | 0.0250 | 3762664 | Symfony\Component\HttpKernel\HttpKernel->handle( ) | ../HttpKernel.php:52 |
6 | 0.0250 | 3762664 | Symfony\Component\HttpKernel\HttpKernel->handleRaw( ) | ../HttpKernel.php:61 |
7 | 0.0689 | 7917464 | call_user_func_array:{/(hidden)/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:117} ( ) | ../HttpKernel.php:117 |
8 | 0.0689 | 7918080 | Drupal\Core\Entity\HtmlEntityFormController->content( ) | ../HttpKernel.php:117 |
9 | 0.0689 | 7918080 | Drupal\Core\Controller\HtmlFormController->content( ) | ../HtmlEntityFormController.php:25 |
10 | 0.0700 | 8114096 | drupal_build_form( ) | ../HtmlFormController.php:68 |
11 | 0.0848 | 9918880 | drupal_process_form( ) | ../form.inc:419 |
12 | 0.1131 | 11691752 | form_execute_handlers( ) | ../form.inc:935 |
13 | 0.1131 | 11692936 | call_user_func_array:{/(hidden)/core/includes/form.inc:1567} ( ) | ../form.inc:1567 |
14 | 0.1131 | 11693000 | Drupal\node\Form\NodeDeleteForm->submit( ) | ../form.inc:1567 |
15 | 0.1132 | 11693000 | Drupal\Core\Entity\Entity->delete( ) | ../NodeDeleteForm.php:94 |
16 | 0.1132 | 11693432 | Drupal\Core\Entity\DatabaseStorageControllerNG->delete( ) | ../Entity.php:436 |
17 | 0.1229 | 12128800 | Drupal\Core\Entity\EntityStorageControllerBase->invokeFieldMethod( ) | ../DatabaseStorageControllerNG.php:598 |
18 | 0.1231 | 12133384 | Drupal\Core\Entity\Field\Field->delete( ) | ../EntityStorageControllerBase.php:148 |
19 | 0.1231 | 12133520 | Drupal\Core\Entity\Field\Field->delegateMethod( ) | ../Field.php:327 |
20 | 0.1231 | 12133520 | Drupal\file\Plugin\field\field_type\FileItem->delete( ) | ../Field.php:346 |
21 | 0.1234 | 12145760 | Drupal\file\FileUsage\DatabaseFileUsageBackend->delete( ) | ../FileItem.php:222 |
Reproduced on several different installs on several machines. Does not happen on a Page node, and it is apparently caused by the file field on articles.
I tried to reproduce it in a webtest, but strangely enough it does not trigger the problem. The patch for the test (which should fail but succeeds) is in the next comment.
Comment | File | Size | Author |
---|---|---|---|
#1 | 0001-Issue-2098655-cannot-delete-article-node-from-UI.patch | 2.55 KB | fgm |
Comments
Comment #1
fgmTest reproducing the steps which fail in the UI, so should fail, but actually passes on my machine. Maybe an error in the test itself.
Comment #2
-enzo- CreditAttribution: -enzo- commentedI reproduce the error with the same conditions mentioned.
[26-Sep-2013 21:43:15 Europe/Berlin] PHP Fatal error: Call to a member function id() on a non-object in /Users/enzo/www/drupal8/core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php on line 73
Comment #3
-enzo- CreditAttribution: -enzo- commentedHey folks
After run a debug backtrace I detect the problem is in file core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php class Drupal\file\FileUsage\DatabaseFileUsageBackend and method delete.
The class don't sent the entity object properly
So the problem is in the line $entity = $this->getRoot();
I don't know where is this method located, if someone can provide an advice about how to fix this issue, I could try.
Comment #4
BerdirIt should probably use getEntity() now, there shouldn't be a difference between the two but you can try?
getRoot() is implemented in TypedData, but that's pretty generic code.
Comment #5
netsensei CreditAttribution: netsensei commentedI'm looking at this same error since noon. I thought it was something on my machine, but apparently it's the code.
I changed the delete() method to read like this:
But that triggers this error:
Comment #6
BerdirI meant to replace getRoot() with getEntity(), not ->entity. getEntity() is badly named for reference fields :(
Comment #7
-enzo- CreditAttribution: -enzo- commentedI tried
$entity = $this->getEntity();
and
$entity = getEntity();
Same error any glue?
Comment #8
netsensei CreditAttribution: netsensei commentedI see. Seems to me that it's getting the entity to which the field is attached rather then the entities it's referencing. So, I agree: the method name definitely needs to be looked at.
Comment #9
netsensei CreditAttribution: netsensei commentedOw, sorry! :-(
Comment #10
BerdirOk, ignore what I said above.
The problem is that we don't have a file reference but we try to remove file usage of it. This is also related to #1988492: Avoid having empty field items by default.
The refactoring in #2073033: Optimize file usage updates in file/image fields fixes this bug, but we need test coverage.
Easy to reproduce fatal errors are critical, so...
Comment #11
claudiu.cristea#2073033: Optimize file usage updates in file/image fields will fix this too. Marked that as critical and this as duplicate.
EDIT: Also added test there to prove the failure/fix.
Comment #12
fgmResetting to fixed so that whoever cared about this gets notification that the refactor in #2073033: Optimize file usage updates in file/image fields actually fixed this issue as expected.