Traceback with read/set user fields in version 6.0 scenarios
Since commit dc5cd56a8923 if we try to read/set a field in the res.user model in a rst, we end with a traceback. How to replicate:
- For this example, we add a new rst test file in the account invoice module:
================
Invoice Scenario
================
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from operator import attrgetter
>>> from proteus import Model, Wizard
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company, \
... get_company
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
... create_chart, get_accounts, create_tax, create_tax_code
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> today = datetime.date.today()
Activate modules::
>>> config = activate_modules('account_invoice')
Read from user::
>>> User = Model.get('res.user')
>>> user, = User.find([])
>>> user.name
Test
Write in user::
>>> User = Model.get('res.user')
>>> user, = User.find([])
>>> user.name = 'Test'
>>> user.save()
- Since we are in the 6.0 version, we need to add the suite in the "test_account_invoice.py":(https://foss.heptapod.net/tryton/tryton/-/blob/branch/6.0/modules/account_invoice/tests/test_account_invoice.py)
suite.addTests(doctest.DocFileSuite(
'scenario_test_user.rst',
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
- When we execute the test, and we try to read the user.name (for example) a traceback is returned:
======================================================================
FAIL: /home/juanjo/Projectes/tryton60/trytond/trytond/modules/account_invoice/tests/scenario_test_user.rst
Doctest: scenario_test_user.rst
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.9/doctest.py", line 2204, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for scenario_test_user.rst
File "/home/juanjo/Projectes/tryton60/trytond/trytond/modules/account_invoice/tests/scenario_test_user.rst", line 0
----------------------------------------------------------------------
File "/home/juanjo/Projectes/tryton60/trytond/trytond/modules/account_invoice/tests/scenario_test_user.rst", line 28, in scenario_test_user.rst
Failed example:
user.name
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python3.9/doctest.py", line 1336, in __run
exec(compile(example.source, filename, "single",
File "<doctest scenario_test_user.rst[13]>", line 1, in <module>
user.name
File "/home/juanjo/Projectes/tryton60/proteus/proteus/__init__.py", line 119, in __get__
instance._read(self.name)
File "/home/juanjo/Projectes/tryton60/proteus/proteus/__init__.py", line 961, in _read
self._proxy.read([self.id], fields, self._context)[0])
File "/home/juanjo/Projectes/tryton60/proteus/proteus/config.py", line 202, in __call__
result = rpc.result(meth(*args, **kwargs))
File "/home/juanjo/Projectes/tryton60/trytond/trytond/modules/company/res.py", line 151, in read
result = super(User, cls).read(ids, fields_names)
File "/home/juanjo/Projectes/tryton60/trytond/trytond/res/user.py", line 364, in read
cache = Transaction().get_cache()[cls.__name__]
File "/home/juanjo/Projectes/tryton60/trytond/trytond/cache.py", line 422, in __missing__
raise KeyError(key)
KeyError: 'res.user'