Problem/Motivation

A 500 error is shown when BibCite keywords are merged using bulk operations (at admin/content/bibcite/keyword)

Steps to reproduce

  1. Create a plain Drupal 9 site
  2. Install Bibcite module: composer require 'drupal/bibcite:^2.0@beta'
  3. Enable all submodules of bibcite
  4. Go to /bibcite/keyword/add to add two keywords (for example: "One" and "Two")
  5. Go to /admin/content/bibcite/reference and add a reference, assigning the keyword "One" to it.
  6. Go to /admin/content/bibcite/keyword, select "One", then select 'Merge keyword' in Action, then click 'Apply to selected items'.
  7. Select target "Two", then click 'Merge'.

It shows error message:
An error has occurred.
Please continue to the error page
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /batch?id=3&op=do_nojs&op=do
StatusText: Internal Server Error
ResponseText: The website encountered an unexpected error. Please try again later.

Step 7: Check admin/reports/dblog. It shows:
Drupal\Core\Entity\Query\QueryException: 'keyword' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 369 of /var/www/html/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork bibcite-3359457

Command icon 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

lily.yan created an issue. See original summary.

lily.yan’s picture

Issue summary: View changes
lily.yan’s picture

We still can merge keywords successfully if we run from the operations in the table instead.

Step 1: Go to admin/content/bibcite/keyword, select 'Merge' under Operations of 'key2'. It goes to admin/content/bibcite/keyword//merge

Step 2: Select target 'key1', then click 'Merge'. It goes to confirm/cancel page. It shows 'Are you sure you want to merge key2 to key1?', Click 'Confirm'. It shows: 'key2 has been successfully merged and deleted.'

thomjjames’s picture

StatusFileSize
new555 bytes

Hi,

Also experiencing this on the views bulk action only. I checked the bibcite_keyword database table and from what I can tell it seems the "keyword" field doesn't exist which is why the query fails when it's looking for the "keyword" field. From looking at the database query it looks like it should point to "id" instead.

It seems like the field_name is passed from the route definition in modules/bibcite_entity/bibcite_entity.routing.yml:

entity.bibcite_keyword.bibcite_merge_multiple_form:
  path: '/admin/content/bibcite/keyword/merge'
  defaults:
    _form: 'Drupal\bibcite_entity\Form\MergeMultipleForm'
    entity_type_id: 'bibcite_keyword'
    field_name: 'keyword'
  requirements:
    _permission: 'administer bibcite_keyword'

Patch attached against 3.0.x branch or this routeSubscriber seems to fix it too:

<?php

namespace Drupal\MODULE\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

class MODULERouteSubscriber extends RouteSubscriberBase {

  public function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('entity.bibcite_keyword.bibcite_merge_multiple_form')) {
      // Change the default 'field_name' to 'id'.
      $route->setDefault('field_name', 'id');
    }
  }

}

Cheers
Tom

lily.yan’s picture

bibcite-keyword-merge-action-3359457-4.patch works for me. Thank you.

mark_fullmer’s picture

Version: 2.0.x-dev » 3.0.x-dev
Assigned: Unassigned » mark_fullmer
Status: Active » Needs review
mark_fullmer’s picture

Assigned: mark_fullmer » Unassigned

Merge request created from the provided patch to confirm automated test coverage.

istryker’s picture

Status: Needs review » Needs work

I can confirm that the error message goes away, but the merge functionality still does not work.

I tested both the `2.x` and `3.x` branches using both approaches suggested in comment #4 (modifying the YAML file and using a `RouteSubscriber`). Neither method resolved the issue.

The interface reports conflicting messages — one indicating success and another stating that the merge failed.
Only local images are allowed.

In the logs, we’re seeing the following PHP warning:

Warning: Undefined array key "target_id" in _bibcite_entity_process_field_value() (line 99 of /modules/contrib/bibcite/modules/bibcite_entity/bibcite_entity.batch.inc)

Adding an isset() check on line 99 (and also on line 123) suppresses the warning, but the merge functionality still fails.

mark_fullmer’s picture

Issue summary: View changes

  • mark_fullmer committed 3ca6197a on 3.0.x
    Issue #3359457 by thomjjames, lily.yan, mark_fullmer: A 500 error is...
mark_fullmer’s picture

Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.