The model API is not working as I would expect.
Upon running
val1 = Pool().get('res.user')(Transaction().user).employee
val2 = Pool().get('res.user').search([
('id', '=', Transaction().user)])[0].employee
val1 is unexpectedly None, while val2 is the correct employee instance. If I reverse the line order, then val1 and val2 both have the correct value.
This is happening within set_user and set_context context managers, and the problem only happens for one Employee. Moving that Employee from one User to another alters which User experiences the discrepancy, yet I cannot find anything unusual about that Employee when comparing all of its fields with another Employee who does not trigger the problem.
When reading all the fields on the User generated the val1 way and comparing them to the fields on the User generated the val2 way all the fields are the same, with the exception of employee and password_hash, which are None on the val1 version.
Can anyone give me insight into what is happening here? Are there any idioms I
should follow to avoid this surprise?
This is happening on trytond 5.0.38.