Loss of data is possible on update.

Created on 21 March 2023, over 1 year ago
Updated 26 July 2023, over 1 year ago

Problem/Motivation

In the \Drupal\sparql_entity_storage\SparqlEntityStorage::doSave there is the following code:

    if (!$entity->isNew()) {
      $this->deleteBeforeInsert($id, $graph_uri);
    }
    try {
      $this->insert($graph, $graph_uri);
      return $entity->isNew() ? SAVED_NEW : SAVED_UPDATED;
    }

The ::insert contains the serialization sequence of the strings. EasyRdf library is quite slow in encoding the strings and can result in a failure. This means that if there is a failure in the insert, the data are lost from the database since Sparql/Virtuoso does not support transactions.

Proposed resolution

Replace the code in ::insert to perform a DELETE .. INSERT if the entity is not new which does not perform any changes if any part of the query fails.

Note that the DELETE..INSERT contains a WHERE clause and has to match entries to delete in order to insert. That means, that in case the entity is new, it should be a simple INSERT query because otherwise, no matches will occur from the WHERE clause and there will be no action performed.

Move the query AFTER the serialization of the data.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇬🇷Greece idimopoulos

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

Comments & Activities

Production build 0.71.5 2024