This happens with the message module, and I don't understand yet why

1) Enable the message module
2) Run this code:

  $message_type = message_type_create('create_node');
  $message_type->save();

  // TODO: Add the message realm field to the bundle. This should be done by
  // the message module itself, but I haven't found the right place to do it
  // yet. 
  message_add_field_message_realm('create_node');

  $message = message_create('create_node', array());
  $message->save(); // This is not saved in the DB.

When I tried to save it myself it writes the record.

  $message = message_create('create_node', array());
  drupal_write_record('message', $message);

Comments

amitaibu’s picture

> Run this code:

You can run this code via message.test

fago’s picture

Sounds strange. 'll have a closer look at it.

fago’s picture

Status: Active » Fixed

ok, I just tried it and with some debugging I found out an exception is thrown during saving:

'SQLSTATE[23000]: Integrity constraint violation: 1048 Column \'message_realm_mid\' cannot be null'

The problem though was, that the entity CRUD API has used an deprecated way of rolling back the transaction. I've just improved that to use the recent way of doing so - just like core - such that those exceptions are thrown + logged to the watchdog now.

  // TODO: Add the message realm field to the bundle. This should be done by
  // the message module itself, but I haven't found the right place to do it
  // yet. 

I think, the best place for this would be hook_message_type_insert(). Though I've to dive into the realms now.

amitaibu’s picture

Ok, now I'm getting the exception, thanks for the quick fix.
But this shows another issue -- the mid is a serial key, so why is it NULL?

> I think, the best place for this would be hook_message_type_insert().

It sounds right, but I'm getting some violation error. I'll also have to dig in :)

amitaibu’s picture

> But this shows another issue -- the mid is a serial key, so why is it NULL?

Erase that, the above is referring to the realm field. Sorry for the confusion.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.