[18.0][FIX] auditlog: Ensure display_name computation works with new record.
This was identified by running base module tests on an odoo:18 container with auditlog installed, yielding:
ERROR odoo odoo.addons.base.tests.test_display_name: FAIL: Subtest TestEveryModel.test_display_name_new_record [`_compute_display_name` doesn't work with new record (first onchange call).] (model='auditlog.http.session')
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/addons/base/tests/test_display_name.py", line 34, in test_display_name_new_record
model.onchange({}, [], fields_spec)
File "/usr/lib/python3/dist-packages/odoo/addons/web/models/models.py", line 1019, in onchange
snapshot1 = RecordSnapshot(record, fields_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/odoo/addons/web/models/models.py", line 1106, in __init__
self.fetch(name)
File "/usr/lib/python3/dist-packages/odoo/addons/web/models/models.py", line 1121, in fetch
self[field_name] = self.record[field_name]
~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/odoo/models.py", line 7076, in __getitem__
return self._fields[key].__get__(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1236, in __get__
self.recompute(record)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1463, in recompute
apply_except_missing(self.compute_value, recs)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1436, in apply_except_missing
func(records)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1485, in compute_value
records._compute_field_value(self)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 5295, in _compute_field_value
fields.determine(field.compute, self)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 110, in determine
return needle(*args)
^^^^^^^^^^^^^
File "/usr/local/src/metricwise/oca/server-tools/auditlog/models/http_session.py", line 24, in _compute_display_name
tz_create_date = fields.Datetime.context_timestamp(httpsession, create_date)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 2400, in context_timestamp
assert isinstance(timestamp, datetime), 'Datetime instance expected'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Datetime instance expected
Note: The newly created tests/test_http.py failed to provoke the issue, so it is necessary to run base tests to confirm the fix.
Hello @StefanRijnhart any update on when this could be merged?
@baptiste-n42 Please have a look at 'Getting your code merged' in https://odoo-community.org/resources/code. You can help by posting your review on the Files Changed tab.
/ocabot merge patch
What a great day to merge this nice PR. Let's do it! Prepared branch 18.0-ocabot-merge-pr-3392-by-StefanRijnhart-bump-patch, awaiting test results.
Congratulations, your PR was merged at c19f1222706899d8352014a5d847e87531978ca5. Thanks a lot for contributing to OCA. ❤️