Skip to content
Snippets Groups Projects
Commit 67c7cea4 authored by Christophe Monniez's avatar Christophe Monniez
Browse files

[FIX] mass_mailing: use a sequence for random sampling

Since Python 3.11, sampling from a set deprecated, the population must
be a sequence.

This commit applies the suggested fix.

Also, the filtering of the deprecation warning about sampling from set
can be disabled when the python version is not 3.9. This warning was
wrongly triggered since 3.9 because recordsets are bot a sequence and a
set.
This was fixed in python 3.10, see https://bugs.python.org/issue42470



closes odoo/odoo#112317

Signed-off-by: default avatarXavier Morel (xmo) <xmo@odoo.com>
parent 482cb08d
No related branches found
No related tags found
No related merge requests found
......@@ -990,7 +990,7 @@ class MassMailing(models.Model):
remaining = set(res_ids).difference(already_mailed)
if topick > len(remaining) or (len(remaining) > 0 and topick == 0):
topick = len(remaining)
res_ids = random.sample(remaining, topick)
res_ids = random.sample(sorted(remaining), topick)
return res_ids
def _get_remaining_recipients(self):
......
......@@ -139,8 +139,10 @@ def init_logger():
# ignore deprecation warnings from invalid escape (there's a ton and it's
# pretty likely a super low-value signal)
warnings.filterwarnings('ignore', r'^invalid escape sequence \'?\\.', category=DeprecationWarning)
# recordsets are both sequence and set so trigger warning despite no issue
warnings.filterwarnings('ignore', r'^Sampling from a set', category=DeprecationWarning, module='odoo')
if sys.version_info[:2] == (3, 9):
# recordsets are both sequence and set so trigger warning despite no issue
# Only applies to 3.9 as it was fixed in 3.10 see https://bugs.python.org/issue42470
warnings.filterwarnings('ignore', r'^Sampling from a set', category=DeprecationWarning, module='odoo')
# ignore a bunch of warnings we can't really fix ourselves
for module in [
'babel.util', # deprecated parser module, no release yet
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment