1

As the title states, I've encountered a weird problem with hook_entity_insert():

Array ( [:db_update_placeholder_0] => 1 [:db_update_placeholder_1] => 127.0.0.1 [:db_update_placeholder_2] =>

I get a error screen, and this is what's displayed when I attempt to use ksm($entity).

I also checked the logs:

Warning: Error while sending QUERY packet. PID=18801 in Drupal\Core\Database\Statement->execute()....

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: CREATE TABLE {cache_config}....

This is troubling, as the custom module I'm developing heavily relies on nodes.

I thought maybe this was an issue with the DB, and so I used a new one, but the problem persist. I'll be attempting to create a new Drupal project using the same modules.

Therefore I'm asking if anyone else have encountered anything similar to this and found a solution?

4
  • ksm() uses a session to store the debug message in the database and this obviously interferes with the code you try to debug. Use other debugging tools like kint() or set a breakpoint in Xdebug.
    – 4uk4
    Commented Feb 20, 2018 at 7:34
  • problem is ksm() is the only code I'm running in the hook (I want to access the newly generated nid value). Also I tried kint(), and the page/browsers freeze, unable to open the collapsible. This is weird because I've worked with D7 entities and had to problems, so these errors are new to me.
    – solaris
    Commented Feb 20, 2018 at 19:33
  • By code interfering I meant any code, not only the code you've placed in the hook. If you are not able to open kint() then you are probably clicking on the plus sign, which tries to open all levels and for an entity this can take some time. Better click somewhere else on the title bar, this opens only the first level.
    – 4uk4
    Commented Feb 20, 2018 at 20:18
  • you're right about the kint(), I shouldn't be clicking the plus sign. However in my case, when I use kint(), it takes me to a different page, than auto redirects to a different page (if it doesn't auto freeze), preventing me from actually reading the kint(). I have however found a weird solution to the ksm() problem which I will answer my own question.
    – solaris
    Commented Feb 20, 2018 at 20:50

1 Answer 1

3

Found another post that provides a solution to my problem: How to preserve kint output upon form submit redirection?

In my case, while

ksm($entity) 

would display nothing, or show errors,

ksm($entity->toArray()) 

seems to display correctly.

I'm a bit baffled myself why this happens, and will continue to investigate.

1
  • 1
    I tried the "toArray" method and worked. Thanks @masterx Commented Nov 28, 2018 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.