diff --git a/odooly.py b/odooly.py index 0074d32..eb0f315 100644 --- a/odooly.py +++ b/odooly.py @@ -1096,7 +1096,7 @@ def sudo(self, user=SUPERUSER_ID): def with_context(self, *args, **kwargs): """Attach to an extended context.""" - context = dict((args[0] or ()) if args else self.env.context, **kwargs) + context = dict(args[0] if args else self.env.context, **kwargs) return self.with_env(self.env(context=context)) def with_odoo(self): diff --git a/tests/test_model.py b/tests/test_model.py index 24e25cc..1ece320 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -1309,8 +1309,11 @@ def test_with_context(self): rec.with_context(lang='fr_CA', prefetch_fields=False).read('name message') rec.with_context(active_id=7, active_ids=[7]).read('name') rec.read('message') + rec.with_context(lang='fr_CA').with_context().read('message') records.read() + self.assertRaises(TypeError, rec.with_context, None) + self.assertCalls( OBJ('foo.bar', 'read', [13, 17], None), OBJ('foo.bar', 'fields_get'), @@ -1319,6 +1322,7 @@ def test_with_context(self): OBJ('foo.bar', 'read', [42], ['name', 'message'], context={'lang': 'fr_CA', 'prefetch_fields': False}), OBJ('foo.bar', 'read', [42], ['name'], context={'active_id': 7, 'active_ids': [7]}), OBJ('foo.bar', 'read', [42], ['message']), + OBJ('foo.bar', 'read', [42], ['message'], context={'lang': 'fr_CA'}), OBJ('foo.bar', 'read', [13, 17], None), ) self.assertOutput('')