https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292023-01-05T11:34:13ZRedmineRedmine - Defect #37165: Can not get anonymous user using User.findhttps://www.redmine.org/issues/37165?journal_id=1090052023-01-05T11:34:13ZThomas Löber
<ul></ul><p>In Redmine 5 the classes are lazily loaded, that means Rails does not know about the <code>AnonymousUser</code> class before it is referenced, and so the <code>SELECT</code> does not take into account that <code>AnonymousUser</code> is part of the STI hierarchy.</p>
<p>Once the <code>AnonymousUser</code> class is loaded, the <code>SELECT</code> works fine.</p>
<pre>
>> AnonymousUser
=> AnonymousUser(id: integer, login: string, hashed_password: string, firstname: string, lastname: string, admin: boolean, status: integer, last_login_on: datetime, language: string, ...
>> User.find(2)
User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND `users`.`id` = 2 LIMIT 1
=> #<AnonymousUser id: 2, login: "", hashed_password: [FILTERED], firstname: "", lastname: "Anonymous", admin: false, status: 0, last_login_on: nil, language: "", auth_source_id: nil, ...>
</pre>