fix: make create_send_msg_jobs actually return row IDs - #8585
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
20ae3c5 to
889578d
Compare
42ebbff to
1ca89ff
Compare
.execute() was returning the number of rows, so usually 1. .insert() is returning the row ID. In most cases it does not matter because the result is checked with .is_empty(), but send_msg_sync() actually uses the row IDs.
1ca89ff to
e657a72
Compare
| chat1.send_msg_sync(msg1) | ||
|
|
||
| lp.sec("ac2: receive message") | ||
| msg_in = ac2._evtracker.wait_next_incoming_message() |
There was a problem hiding this comment.
The test gets stuck without the fix, likely here because the message is never sent out as it tries to send rowid 1 from smtp table.
|
Ended up writing a python test for dc_send_msg_sync() because it is the only API that is affected and only exists as CFFI. IIRC it is used by iOS for share extension. |
| sent_id = lib.dc_send_msg_sync(self.account._dc_context, self.id, msg._dc_msg) | ||
| if sent_id == 0: | ||
| raise ValueError("message could not be sent") | ||
| # modify message in place to avoid bad state for the caller |
There was a problem hiding this comment.
This code is copy-pasted from a function above.
hpk42
left a comment
There was a problem hiding this comment.
looks good enough (see review comments). Also i think it'd be good to have an offline Rust test queuing two messages and testing the row-id behaviour.
| ac1.stop_io() | ||
| msg1 = Message.new_empty(ac1, "text") | ||
| msg1.set_text("message1") | ||
| chat1.send_msg_sync(msg1) |
There was a problem hiding this comment.
i'd assert that msg1.is_out_delivered() to not land in receive-timeout if something goes wrong.
| def send_msg(self, msg: Message) -> Message: | ||
| """send a message by using a ready Message object. | ||
|
|
||
| :param msg: a :class:`deltachat.message.Message` instance | ||
| previously returned by | ||
| e.g. :meth:`deltachat.message.Message.new_empty`. | ||
| :raises ValueError: if message can not be sent. | ||
|
|
||
| :returns: a :class:`deltachat.message.Message` instance as | ||
| sent out. This is the same object as was passed in, which | ||
| has been modified with the new state of the core. | ||
| """ | ||
| sent_id = lib.dc_send_msg(self.account._dc_context, self.id, msg._dc_msg) | ||
| if sent_id == 0: | ||
| raise ValueError("message could not be sent") | ||
| # modify message in place to avoid bad state for the caller | ||
| sent_msg = Message.from_db(self.account, sent_id) | ||
| if sent_msg is None: | ||
| raise ValueError("cannot load just sent message from the database") | ||
| msg._dc_msg = sent_msg._dc_msg | ||
| return msg | ||
|
|
||
| def send_msg_sync(self, msg: Message) -> Message: | ||
| """Send a message synchronously. | ||
| This bypasses the IO scheduler and creates its own SMTP connection. | ||
|
|
||
| :param msg: a :class:`deltachat.message.Message` instance | ||
| previously returned by | ||
| e.g. :meth:`deltachat.message.Message.new_empty`. | ||
| :raises ValueError: if message can not be sent. | ||
|
|
||
| :returns: a :class:`deltachat.message.Message` instance as | ||
| sent out. This is the same object as was passed in, which | ||
| has been modified with the new state of the core. | ||
| """ | ||
| sent_id = lib.dc_send_msg_sync(self.account._dc_context, self.id, msg._dc_msg) | ||
| if sent_id == 0: | ||
| raise ValueError("message could not be sent") | ||
| # modify message in place to avoid bad state for the caller | ||
| sent_msg = Message.from_db(self.account, sent_id) | ||
| if sent_msg is None: | ||
| raise ValueError("cannot load just sent message from the database") | ||
| msg._dc_msg = sent_msg._dc_msg | ||
| return msg |
There was a problem hiding this comment.
this is almost complete duplication. except for one different lib call. Please consider avoiding it.
.execute() was returning the number of rows, so usually 1.
.insert() is returning the row ID.
In most cases it does not matter because the result is checked with .is_empty(), but send_msg_sync() actually uses the row IDs.