[19.0] mail_tracking: NotNullViolation on mail_notification.notification_type when the tracked partner is not a notified partner of the message

Aperta
#267 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@skanndar ci sta già lavorando.

Dal 23/9/2026.

  • #273 di @skanndar — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, python
Ambito
backend, databases

Direzione di ricerca

Start in mail_tracking/models/mail_tracking_email.py, at MailTrackingEmail._message_partners_check(), and trace the success path from _tracking_sent_prepare. Read the notified_partner_ids field declaration in addons/mail/models/mail_message.py and its Many2many write behavior to understand the constraint failure. Add a regression test for a recipient not already notified, and verify sending succeeds with a valid notification or without linking one.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Module: mail_tracking (branch 19.0, checked at ee6a0e79)
Odoo: 19.0 Community, image odoo:19 build 19.0-20260817, clean database, mail_tracking
only (its single dependency is mail)

Summary

MailTrackingEmail._message_partners_check() adds the tracked partner to the message with

mail_message.sudo().write({"notified_partner_ids": [Command.link(self.partner_id.id)]})

mail.message.notified_partner_ids is not the mail.notification One2many: it is a
Many2many declared over the mail_notification table itself
(addons/mail/models/mail_message.py). Writing to it therefore performs a raw INSERT of the two
foreign keys only (odoo/orm/fields_relational.py::Many2many.write_real), bypassing the ORM and
the default='inbox' of mail.notification.notification_type, which is required=True. The
insert violates the NOT NULL constraint and aborts the whole transaction, so the mail is not
sent and every subsequent query in the same cursor fails with InFailedSqlTransaction.

Steps to reproduce (clean database, no other addon)
  1. Install mail_tracking only.
  2. Create two partners with an email, A and B.
  3. Create a mail.message on any record with a subtype_id (e.g. mail.mt_comment) whose
    partner_ids contain A but not B.
  4. Create a mail.mail linked to that message with recipient_ids = [B].
  5. Send it successfully (any working SMTP; the failure happens on the success path, in
    _tracking_sent_prepare).

Observed: psycopg2.errors.NotNullViolation: null value in column "notification_type" of relation "mail_notification" violates not-null constraint, raised from
mail_tracking/models/mail_tracking_email.py::_message_partners_check (traceback above).

Expected: the partner is linked with a valid mail.notification, or is not linked at all.

Why it is not seen every day

In the normal chatter flow every recipient already has a mail.notification, so
self.partner_id in mail_message.notified_partner_ids | mail_message.partner_ids is true and the
write() never runs. It fires as soon as a mail.mail attached to a message with a subtype is
sent to a partner that was not notified — resend flows, custom queues, hand-built mail.mail.

Suggested fix

Create the notification through the model instead of the relation table, e.g.

self.env["mail.notification"].sudo().create({
    "mail_message_id": mail_message.id,
    "res_partner_id": self.partner_id.id,
    "notification_type": "email",
    "notification_status": "sent",
})

which also gives the chatter a correct status for that recipient (which is the stated intent of
the method: "add it in order to see his tracking status in chatter").

Lingua principale
Python
Stelle
36
Fork
180
Merge medio
4g 2h
PR unite (30g)
14

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OCA/mail

Tutte le issue di OCA/mail

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.