From 2646a34cf08dc1c0f4d993d73f50824aee16d053 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 11 Oct 2011 10:48:52 +0200 Subject: [PATCH] [ADD] don't blow up on a singleton DELETE_ALL command (that command takes no parameters, so can have just (5,)) bzr revid: xmo@openerp.com-20111011084852-hborz317ru5pbzux --- openerp/osv/orm.py | 3 +++ tests/test_orm.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 8a447a838d5..39d05eab839 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -4790,6 +4790,9 @@ class BaseModel(object): for o2m_command in o2m_commands: if not isinstance(o2m_command, (list, tuple)): commands.append((4, o2m_command, False)) + elif len(o2m_command) == 1: + (command,) = o2m_command + commands.append((command, False, False)) elif len(o2m_command) == 2: command, id = o2m_command commands.append((command, id, False)) diff --git a/tests/test_orm.py b/tests/test_orm.py index 1954e485e69..6e82bb9996b 100644 --- a/tests/test_orm.py +++ b/tests/test_orm.py @@ -141,6 +141,16 @@ class TestO2MSerialization(unittest2.TestCase): {'id': ids[2], 'name': 'baz'} ]) + def test_singleton_commands(self): + "DELETE_ALL can appear as a singleton" + + try: + list(self.partner.resolve_o2m_commands_to_record_dicts( + self.cr, UID, 'address', [(5,)], ['name'])) + except AssertionError: + # 5 should fail with an assert error, but not e.g. a ValueError + pass + def test_invalid_commands(self): "Commands with uncertain semantics in this context should be forbidden" @@ -159,3 +169,4 @@ class TestO2MSerialization(unittest2.TestCase): with self.assertRaises(AssertionError): list(self.partner.resolve_o2m_commands_to_record_dicts( self.cr, UID, 'address', [REPLACE_WITH([42])], ['name'])) +