[19.0] mail_tracking: NotNullViolation on mail_notification.notification_type when the tracked partner is not a notified partner of the message
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
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)
- Install
mail_trackingonly. - Create two partners with an email,
AandB. - Create a
mail.messageon any record with asubtype_id(e.g.mail.mt_comment) whose
partner_idscontainAbut notB. - Create a
mail.maillinked to that message withrecipient_ids = [B]. - 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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di OCA/mail
-
[18.0] mail_drop_target: uploading a file to a Discuss channel fails (_get_as_sudo_from_request_or_raise no longer exists)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
gorakhargosh/watchdog#1462 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
openwisp/openwisp-monitoring#889 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
OpenFreeEnergy/Lomap#180 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
roman-corgi/corgisim#327 ·
I maintainer di solito rispondono entro 2 giorni
-
agent:WSL bug code-review linux pri:medium sev:low tooling
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno