TypeError: Drupal\sparql_entity_storage\Entity\Query\Sparql\SparqlArg::uri()

Created on 6 September 2023, 10 months ago
Updated 13 October 2023, 9 months ago

Problem/Motivation

Indexing with Search API Solr causes the following error:

TypeError: Drupal\sparql_entity_storage\Entity\Query\Sparql\SparqlArg::uri(): Argument #1 ($uri) must be of type string, int given, called in /modules/contrib/sparql_entity_storage/src/Entity/Query/Sparql/SparqlArg.php on line 62 in Drupal\sparql_entity_storage\Entity\Query\Sparql\SparqlArg::uri() (line 76 of /modules/contrib/sparql_entity_storage/src/Entity/Query/Sparql/SparqlArg.php)

Steps to reproduce

Run indexing on drupal 9.5.7, Search API Solr

Proposed resolution

public static function toResourceUris(array $uris): array {
foreach ($uris as $index => $uri) {
if (is_string($uri)) {
$uris[$index] = self::uri($uri);
}
}
return $uris;
}

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡·πŸ‡΄Romania iuliad

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

Comments & Activities

  • Issue created by @iuliad
  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    Build Successful
  • @elber opened merge request.
  • Status changed to Needs review 10 months ago
  • πŸ‡§πŸ‡·Brazil elber Brazil
  • πŸ‡·πŸ‡΄Romania iuliad
  • πŸ‡·πŸ‡΄Romania iuliad
  • πŸ‡¬πŸ‡·Greece idimopoulos

    @elber may I ask what you are trying to achieve? SPARQL is supposed to work with string IDs and more specifically, adhere to the RDF standard that the entity ID is a URI mainly.
    Now, that does not mean that a resource URI cannot be a number, for example "<44>", however, it might be preferable to adapt the entity IDs to be string before they are passed in the method here. Further more, the code you provided, will not construct the <resource> resource URI (encapsulated with <>). Does this even work? I don't think it makes a valid RDF scheme to have data with simple numeric ID.
    If you still need them to be numeric ID though, I think you should use some hook_entity_load in order to typecast the ID.

Production build 0.69.0 2024