[FIX] generate_tracking_message_id: use more randomness to avoid duplicates

When several message IDs had to be generated for the same
record at the same time, there was a high chance to
get non-unique results. This possibly lead to data loss because
some mail implementations might ignore multiple mails with the
same ID (including OpenERP itself). On most operating systems
the available time resolution precision is better than what
we used (due to the float rounding of `%s`).
Adding a bit of randomness doesn't hurt, as OpenERP will
be used in increasingly distributed environments, so
we now add an extra random part as well.

bzr revid: odo@openerp.com-20121022162421-qr7nq8idihp5781u
This commit is contained in:
Olivier Dony 2012-10-22 18:24:21 +02:00
parent 6280e223be
commit b5b19a7a01
1 changed files with 7 additions and 10 deletions

View File

@ -27,12 +27,11 @@ Miscellaneous tools used by OpenERP.
"""
from functools import wraps
import inspect
import subprocess
import logging
import os
import random
import re
import smtplib
import socket
import sys
import threading
@ -40,13 +39,6 @@ import time
import zipfile
from collections import defaultdict
from datetime import datetime
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart
from email.Header import Header
from email.Utils import formatdate, COMMASPACE
from email import Utils
from email import Encoders
from itertools import islice, izip
from lxml import etree
from which import which
@ -363,7 +355,12 @@ def generate_tracking_message_id(res_id):
Used to track the replies related to a given object thanks to the "In-Reply-To"
or "References" fields that Mail User Agents will set.
"""
return "<%s-openerp-%s@%s>" % (time.time(), res_id, socket.gethostname())
try:
rnd = random.SystemRandom().random()
except NotImplementedError:
rnd = random.random()
rndstr = ("%.15f" % rnd)[2:]
return "<%.15f.%s-openerp-%s@%s>" % (time.time(), rndstr, res_id, socket.gethostname())
def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False,
attachments=None, message_id=None, references=None, openobject_id=False, debug=False, subtype='plain', headers=None,