eZ Platform Discussions

DB throws an Exception


#1

We’re using current eZ platform 2.5 and are facing a db exception.

"Object of class eZ\Publish\Core\FieldType\Relation\Value could not be converted to int"

I dont have a clue how to debug this, because the logs dont give any hint – bin/console server:log -vvv even does not print anything else than thousands of deprecation messages in eZ code :confused:

The actual db statement executes well in mysql client, there must happen something while comparing, validating or type casting the results.

Statement is:

 SELECT c.*, t.main_node_id AS ezcontentobject_tree_main_node_id 
 FROM ezcontentobject c 
 LEFT JOIN ezcontentobject_tree t 
    ON (c.id = t.contentobject_id) AND (t.node_id = t.main_node_id) 
 WHERE c.id = ?' 
 with params [{"destinationContentId":7253}]

Stacktrace comes from our template

{{ render(controller('image:getGallery', {'contentId': content.getFieldValue("gallery_category" ) })) }}

walks over TreeHandler.php (line 90)

public function loadContentInfo($contentId){
    return $this->contentMapper->extractContentInfoFromRow(
        $this->contentGateway->loadContentInfo($contentId)
    )
}

and ends at PDOStatement.php (line 117)

public function execute($params = null)
{
    try {
        return parent::execute($params);              <--------------------
    } catch (\PDOException $exception) {
        throw new PDOException($exception);
    }
}

We updated the DB from eZ publish/platform 5.4 via 6.13 and 1.7. Maybe there’s a schema change missing but I grepped the available dbupdate.sql scripts w/o results.

Crazy sidenode: after calling this location in admin and therefor loaded into cache, the problem disappears in frontend. Roles and policies are double checked.

So if anybody has an idea how to investigate further please tell me, any help is appreciated.


#2

Hi! It might be useful to have a more complete stack trace. You call it a DB exception, what is the actual name of it? PDOException?

If the exception happens when PDO is dealing with the statement you show, then it’s clear that someone or something is passing a Relation Value as a destination content ID. The Value is an object and probably can’t be cast to int.

Assuming the template code is the source of problem, then the “contentId” should be an int. Try debugging

content.getFieldValue("gallery_category" )

If that’s an object, then that’s your problem, and you’d need to get the int property from it.


#3

Thanks a load for your suggestions. It’s a DBALException not a PDOException . There are four StackTraces exposed:

  1. Twig\Error\ RuntimeError
  2. RunTimeException
  3. DBALException
    An exception occurred while executing ‘SELECT c.*, t.main_node_id AS ezcontentobject_tree_main_node_id FROM ezcontentobject c LEFT JOIN ezcontentobject_tree t ON (c.id = t.contentobject_id) AND (t.node_id = t.main_node_id) WHERE c.id = ?’ with params [{“destinationContentId”:7253}]: Notice: Object of class eZ\Publish\Core\FieldType\Relation\Value could not be converted to int
  4. ContextErrorException
    Notice: Object of class eZ\Publish\Core\FieldType\Relation\Value could not be converted to int

I could post any, if you want.

But your answer points to a possible misunderstanding by me. Shouldn’t the query params debug string which reads

… WHERE c.id = ?’ with params [{“destinationContentId”:7253}]

be

 … WHERE c.id = ?’ with params [7253]

Does this indicate that I pass an object?


#4

I think you’re right, it should be as you say. The value you are seeing looks like a JSON-encoded object. The class eZ\Publish\Core\FieldType\Relation\Value has only one property: destinationContentId. Ref

It does allow implicit casting to string, which in turn could be cast to int.

I would still debug content.getFieldValue(“gallery_category” ) and see exactly what it is. Then you could try casting to string in the template, by adding “.__toString”.


#5

You’re right, thx a huge load!