worker: fix reparenting for out-of-order emails
The current reparenting approach sometimes doesn't work. This commit fixes three issues in the implementation: 1. If an email is being reparented that was previously the root of a thread, then it's `thread_id` is `None`. In this case, add its `id` to the list of thread IDs to update. 2. The update statement's where clause uses an `in` expressions, which is evaluated by Python immediately. Instead, use the `.in_` function. 3. The update statement is not tied to the session and never gets executed. Explicitly `execute()` it.
This commit is contained in:
parent
02395e0471
commit
ec2811f395
|
@ -264,10 +264,13 @@ def _archive(dest, envelope, do_webhooks=True):
|
|||
for child in children:
|
||||
child.parent_id = mail.id
|
||||
if child.thread_id != thread.id:
|
||||
ex_threads.update({ child.thread_id })
|
||||
ex_thread_id = child.thread_id if child.thread_id else child.id
|
||||
ex_threads.update({ ex_thread_id })
|
||||
child.thread_id = thread.id
|
||||
(Email.__table__.update().where(Email.thread_id in ex_threads)
|
||||
.values(thread_id=thread.id))
|
||||
if len(ex_threads) > 0:
|
||||
db.session.execute(Email.__table__.update()
|
||||
.where(Email.thread_id.in_(ex_threads))
|
||||
.values(thread_id=thread.id))
|
||||
|
||||
db.session.flush()
|
||||
# Update thread nreplies & nparticipants
|
||||
|
|
Loading…
Reference in New Issue