[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
This commit is contained in:
Xavier Morel 2011-10-11 10:48:52 +02:00
parent 8734ffb6c2
commit 2646a34cf0
2 changed files with 14 additions and 0 deletions

View File

@ -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))

View File

@ -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']))