AJAX error: 403 / Not all entities appear to belong to the same entity type.

Created on 12 February 2021, almost 4 years ago
Updated 14 April 2023, over 1 year ago

I followed the instructions on the module home page to the letter.
When I tried to sort I get an AJAX error in the console:

An AJAX HTTP error occurred.
HTTP Result Code: 403
Debugging information follows.
Path: /sortableviews/ajax
StatusText: error
ResponseText: {"message":"Not all entities appear to belong to the same entity type."}"

The 403 would suggest an access permission issue but the message suggests I'm trying to sort different entity types.

My sortable view contains only nodes of one specific content type so I'm not sure why this error would coming up?

Wanted to log the issue here in case anyone else has had the same. If I find the solution I'll be back to report on the fix.

🐛 Bug report
Status

Postponed: needs info

Component

Code

Created by

🇬🇧United Kingdom darren.fisher

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium dieterholvoet Brussels

    This error is triggered if the amount of ids which is passed to the backend doesn't match the amount of loaded entities:

    // Load all entities in $current_order.
        $entities = $this->entityManager->getStorage($base_entity_type->id())->loadMultiple(array_values($current_order));
        if (count($entities) != count($current_order)) {
          return AccessResult::forbidden()->setReason('Not all entities appear to belong to the same entity type.')->setCacheMaxAge(0);
        }
    

    This could happen if the passed entity ID's are from multiple entity types, which would mean that part of the entity ID's doesn't correspond to an actual entity. This isn't possible in views though, so maybe the best solution would be to remove that check.

    This can also happen if an entity listed in the view has been deleted in the meantime. In that case, I think we should just silently skip that ID. Another use case supporting the removal of this check.

    I had the same issue with nodes with translations. I created the view to filter to the default language (English) and the error went away and the weights were saved.

    This error can also happen if your view lists the same entity multiple times, in multiple languages, since only the ID is sent to the backend. Ideally that would be an ID/langcode combination. I suggest we fix that in Save translated version of entity, if one exists Needs work .

    i have the same issue, but the view already has a filter to the default language set.

    Do you have any idea why the same entity would be listed more than once in your view? Maybe this was a case where an entity was deleted and the view was saved without reloading the page?

Production build 0.71.5 2024