Skip to content

Commit

Permalink
Do not accept .with_context(None), partial revert of 8bd4569
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Dec 27, 2018
1 parent bbb5164 commit a40659c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion odooly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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('')
Expand Down

0 comments on commit a40659c

Please sign in to comment.