I ran into a problem where field_purge_batch() was called during cron, and expecting to delete all data related to field_xyz. The problem was that the table field_data_field_xyz did not exist on my site, so an exception was thrown.
Here are some symptoms:
(1) field_purge_batch(10) returns an exception
(2) field_read_instances(array('deleted' => 1), array('include_deleted' => 1)) returns field_xyz, but field_xyz's corresponding field_data_field_xyz table does not exist.
(3)
$ drush cron;
WD cron: PDOException: SQLSTATE[42S02]: Base table or view not found:[error]
1146 Table 'field_data_field_xyz' doesn't exist:
SELECT DISTINCT field_data_field_xyz0.entity_type AS
entity_type, field_data_field_xyz0.entity_id AS
entity_id, field_data_field_xyz0.revision_id AS
revision_id, field_data_field_xyz0.bundle AS bundle
FROM
{field_data_field_xyz}
field_data_field_xyz0
WHERE (field_data_field_xyz0.deleted =
:db_condition_placeholder_0) AND
(field_data_field_xyz0.bundle =
:db_condition_placeholder_1)
LIMIT 10 OFFSET 0; Array
(
[:db_condition_placeholder_0] => 1
[:db_condition_placeholder_1] => stm_tarif_page
)
in field_sql_storage_field_storage_query() (line 585 of
/path/to/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).
Table 'stm.field_data_field_stm_tarifs_lignes' doesn't exist
I have no idea why field_data_field_xyz did not exist, perhaps because of an interrupted previous cleanup attempt, but at this point if the table does not exist, might it be OK to simply assume that there is no data?
Comment | File | Size | Author |
---|---|---|---|
#21 | 1994522-purge-batch-or-deleted-field.patch | 2.19 KB | ricardofaria |
#20 | 1994522-d95-20.patch | 2.21 KB | nagy.balint |
#15 | 1994522-15.patch | 1.13 KB | ranjith_kumar_k_u |
#5 | when_purging_a_batch_of-1994522-4.patch | 1.09 KB | finne |
#1 | core--7.x--1994522-1--check-table-exists-before-deleting-data.patch | 1.28 KB | alberto56 |
Comments
Comment #1
alberto56 CreditAttribution: alberto56 commentedComment #2
alberto56 CreditAttribution: alberto56 commentedThe above test just makes sure the table exists before attempting to delete its data, which prevents field_purge_batch(10) from throwing an exception during cleanup.
Comment #4
finneI ran into this same issue in the current 8.x versions of Drupal.
People might delete some of these tables by hand or using another method. If these tables are missing purging deleted tables will fail with an SQL exception. I would propose that we be more lenient and try to continue after a delete call to a missing deleted field table.
See also related issues https://www.drupal.org/node/2862308 , https://www.drupal.org/node/2836539 and https://www.drupal.org/node/2622160 .
Comment #5
finneHere's a patch that checks for missing field tables if the field is marked deleted and logs an error in the watchdog and continues afterwards.
Comment #6
finneComment #15
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedRe-rolled the last patch for 9.3
Comment #16
quietone CreditAttribution: quietone as a volunteer commentedI wonder if this is actually a bug.
This will need a test, adding tag. I though it would be easy to add a test to the existing one but I was not able to find an existing test for purging the field tables.
This can be combined to one comment at the beginning of the if block. Maybe something like this,
'//If the table does not exist just log a message.'
Is this an error or a warning?
Comment #20
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedIt seems that it is also possible that the storage itself is missing and getFieldStorageDefinition throws a FieldException
So I added an extra try catch block there, as if there is no storage, then also nothing to do I guess.
for now the patch is for 9.5.
Comment #21
ricardofaria CreditAttribution: ricardofaria at Cyber-Duck commentedAdding a patch for drupal 10.1.x
Comment #23
mglamanThis happened to me where the field storage was purged even though the deleted fields repository was tracking a field definition. I don't know the root cause. It may be due to cron running at the same time in the background and processing
field_cron
while the UI is also handling the field purge as well.There is no lock used for this process to prevent duplicate purge runs on specific fields.
Edit: Example of adding a lock
Comment #24
andypost