Background: RDF_sync module worked well before I accidentally removed the Virtuoso container and lost all the synchronized RDF data. I re-run a new Virtuoso container and connected it with Drupal. I tried manually batch write all my mapped nodes into Virtuoso as below:
vendor/bin/drush rdf_sync:synchronize node
It showed error as below:
In ProcessBase.php line 171:
Unable to decode output into JSON: Syntax error
TypeError: Drupal\rdf_sync\RdfSyncSynchronizer::Drupal\rdf_sync\{closure}(): Return value must be of type string, null returned in Drupal\rdf_sync\RdfSyncSynchronizer->Drupal\rdf_sync\{closure}() (line 122 of /var/www/ht
ml/drupal/web/modules/contrib/rdf_sync/src/RdfSyncSynchronizer.php).
Fatal error: Uncaught TypeError: Drupal\rdf_sync\RdfSyncSynchronizer::Drupal\rdf_sync\{closure}(): Return value must be of type string, null returned in /var/www/html/drupal/web/modules/contrib/rdf_sync/src/RdfSyncSync
hronizer.php:122
Stack trace:
#0 [internal function]: Drupal\rdf_sync\RdfSyncSynchronizer->Drupal\rdf_sync\{closure}()
#1 /var/www/html/drupal/web/modules/contrib/rdf_sync/src/RdfSyncSynchronizer.php(119): array_map()
#2 /var/www/html/drupal/web/modules/contrib/rdf_sync/src/RdfSyncSynchronizer.php(104): Drupal\rdf_sync\RdfSyncSynchronizer->doSynchronize()
#3 /var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php(51): Drupal\rdf_sync\RdfSyncSynchronizer->destruct()
#4 [internal function]: Drupal\Core\EventSubscriber\KernelDestructionSubscriber->onKernelTerminate()
#5 /var/www/html/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#6 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(115): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#7 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(63): Symfony\Component\HttpKernel\HttpKernel->terminate()
#8 /var/www/html/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(688): Drupal\Core\StackMiddleware\StackedHttpKernel->terminate()
#9 /var/www/html/drupal/vendor/drush/drush/src/Boot/DrupalBoot8.php(326): Drupal\Core\DrupalKernel->terminate()
#10 [internal function]: Drush\Boot\DrupalBoot8->terminate()
#11 {main}
thrown in /var/www/html/drupal/web/modules/contrib/rdf_sync/src/RdfSyncSynchronizer.php on line 122
When I created a node in Drupal Web UI, it was synchronized into Virtuoso.
Is it because there are many entity_reference fields between bundles? (Edit: Because when I manually added a new node, it did write RDF into Virtuoso.)
Issue fork rdf_sync-3472816
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
Comment #2
claudiu.cristeaI need more context to understand your case
Comment #3
claudiu.cristeaAlso, could you, please, enter a proper title for this issue and not paste the error message. Thanks
Comment #4
fishfree commentedComment #5
fishfree commentedComment #6
claudiu.cristeaThis happens when one ore more nodes don't have a corresponding record in the
rdf_sync_uritable (or for some reason the uri column is empty). Check and fix those casesComment #7
claudiu.cristeaI have decided to give a 2nd look at this. I think it would be correct to handle the case when, accidentally, some entities URIs were lost and prevent any ugly error.
Comment #10
claudiu.cristeaThank you for reporting
Comment #11
fishfree commented@claudiu Thank you! After apply your patch, my error turned into:
Comment #12
claudiu.cristeaI see the same bug in my project :(
Comment #14
claudiu.cristea@fishfree, could you, please, test the latest MR?
Comment #15
fishfree commented@claudiucristea Thank you very much! Would you pls share a single patch file against the version https://www.drupal.org/project/rdf_sync/releases/1.0.0-alpha12 ? Sorry I'm not able to manually merge your multiple MRs.
Comment #16
claudiu.cristeaYou should just go to MR and append .diff to URL
Comment #17
fishfree commented@claudiucristea Thank you very much! After applying https://git.drupalcode.org/project/rdf_sync/-/merge_requests/25.diff based on https://www.drupal.org/project/rdf_sync/releases/1.0.0-alpha12, I re-run
vendor/bin/drush rdf_sync:synchronize nodeIt showed as below:
I checked in my Virtuoso, it seems all the 1965 entities had been synchonized. Why still the error occured?
Comment #18
dimilias commentedHello @fishfree
From what I see, it seems that you might not have a URI for all entities. Probably you can check directly by running a quick query like
if we are talking about nodes and re run this for every bundle to see which IDs are empty.
Furthermore, I created the following script (works for me with nodes) to iterate through all entity types in order to check all of them for empty URIs. Sorry for all the container calls, it was created in haste. After running it with
drush php:script ./my-script.phpand you verify if I am correct, you can also uncomment the commented section designated, to also create URIs for the IDs that are missing them and update the entities. Please, note, that this will actually update the entities. If you do not wish them updated, adjust accordingly or manually force the values in therdf_sync_uritable.Further more, in https://www.drupal.org/project/rdf_sync/issues/3478179, we are working on allowing a subscriber to tamper with the entities before syncing them. That means, that using this subscriber, and a simple check whether the entity does have a URI, you can either identify or block the entity from being synced.
Please, consider that, the error you are getting is based on the idea that having a bundle synced, all entities should have a URI. That is why if a bundle is mapped, the
getUrishould always return a value and we do not allow it to return null. That is because a URI is like a persistent identifier in RDF data and thus we thought we should be strict with it.This might be that the URI was removed somewhere along the way or that Virtuoso already had the data before you sync. If you are using docker, and the container crashed, it doesn't mean data were deleted if the volume remained intact.
Also, if the functionality was enabled after a few entities were created, and are left without a URI from the beginning, the whole rdf_sync would work in general, but the mass export would fail.
I mean, we would need more information to identify further issues.
In terms of this ticket, I will review the second MR because in the first one, the deletion of triples was removed and now data cannot be removed when the entity is deleted.
Comment #19
dimilias commentedWe have discussed with Claudiu, I will merge MR 25 and will continue to https://www.drupal.org/project/rdf_sync/issues/3478179 to conclude the tests.
Comment #21
dimilias commentedSorry, here is an updated script that works. I tested it in my case (I managed to replicate it by tampering with the data in the table)
Comment #22
claudiu.cristea@fishfree, did you try to test with suggestions from @idimopoulos? I want to close this issue.
Comment #23
fishfree commentedFor me, the problem still exists after upgrading to the latest dev version of rdf_sync and running
vendor/bin/drush php:script ./my-script.php.Comment #24
claudiu.cristeaWe cannot do anything else here. If you can give us more details, let us know