AccountInterface::getLastAccessedTime() implementors return incorrect data type [#2954725] | Drupal.org
Skip to search
Can we use first and third party cookies and web beacons to
understand our audience, and to tailor promotions you see
AccountInterface::getLastAccessedTime() implementors return incorrect data type
Patch (to be ported)
Project:
Drupal core
Version:
11.x-dev
Component:
user system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
DX (Developer Experience)
Bug Smash Initiative
about tags
DX (Developer Experience)
Enhances
developer experience
Reporter:
manuel.adan
Created:
20 Mar 2018 at 22:06 UTC
Updated:
20 Apr 2026 at 22:21 UTC
Jump to comment:
Most recent
Most recent file
Problem/Motivation
According to
documentation
, User::getLastAccessedTime returns 0 if the user has never accessed the site:
A value of 0 means the user has never accessed the site
But in fact, the returned value in such case is '0' (string). And for users that accessed the site, the returned timestamp is also a string, when the expected returned value type is integer:
Return value
int Timestamp of the last access.
This is not accurate and makes it fail in some scenarios, like strict comparisons.
Steps to reproduce
After logging into a site as user 1, execute this Drush command:
drush eval "var_dump(\Drupal\user\Entity\User::load(1)->getLastAccessedTime());"
. The dumped value is a string, not an int.
Proposed resolution
Cast the returned type to integer.
Change the
\Drupal\Core\Session\UserSession::$access
type to
int
Remaining tasks
Review
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Comment
File
Size
Author
#30
2954725-nr-bot_wcz9k384.txt
1.06 KB
needs-review-queue-bot
#19
interdiff_18-19.txt
729 bytes
vsujeetkumar
#19
2954725-19.patch
1.28 KB
vsujeetkumar
#18
2954725-18.patch
442 bytes
akashkumar07
#6
2954725-6.patch
442 bytes
ravi.shankar
#2
2954725-2.patch
436 bytes
manuel.adan
Issue fork
drupal-2954725
Show commands
Start within a Git clone of the project using the
version control instructions
Add & fetch this issue fork’s repository
Or,
if you do not have
SSH keys set up on git.drupalcode.org
Add & fetch this issue fork’s repository
1 hidden branch
2954725-fix-getlastaccessedtime
plain diff
MR
!13712
Check out this branch for the first time
Check out existing branch, if you already have it locally
About issue forks
Comments
Comment
#1
20 March 2018 at 22:06
manuel.adan
created an issue. See
original summary
or
to post comments
Comment
#2
manuel.adan
commented
20 March 2018 at 22:07
Assigned:
manuel.adan
» Unassigned
Status:
Active
» Needs review
Status
File
Size
new
2954725-2.patch
436 bytes
or
to post comments
Comment
#3
20 March 2018 at 22:57
Status:
Needs review
» Needs work
The last submitted patch,
2: 2954725-2.patch
, failed testing.
View results
or
to post comments
Comment
#4
20 March 2018 at 22:57
Version:
8.6.x-dev
» 8.7.x-dev
Drupal 8.6.0-alpha1
will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the
Drupal 8 minor version schedule
and the
Allowed changes during the Drupal 8 release cycle
or
to post comments
Comment
#5
20 March 2018 at 22:57
Version:
8.7.x-dev
» 8.8.x-dev
Drupal 8.7.0-alpha1
will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the
Drupal 8 minor version schedule
and the
Allowed changes during the Drupal 8 release cycle
or
to post comments
Comment
#6
ravi.shankar
commented
31 August 2019 at 19:47
Status:
Needs work
» Needs review
Status
File
Size
new
2954725-6.patch
442 bytes
I have done patch on Drupal 8.8.x-dev
or
to post comments
Comment
#7
31 August 2019 at 20:51
Status:
Needs review
» Needs work
The last submitted patch,
6: 2954725-6.patch
, failed testing.
View results
or
to post comments
Comment
#8
dpi
Perth, Australia
commented
5 September 2019 at 03:10
Title:
User::getLastAccessedTime() returns string instead of integer
» AccountInterface::getLastAccessedTime() implementors return incorrect data type
Issue tags:
DX
Change looks good, but needs work.
I think we should go ahead and fix the documentation for
\Drupal\Core\Session\UserSession::$access
, which claims the value is a string, and check for any created
User
UserSession
objects initialised with 'access' => string
or
to post comments
Comment
#9
5 September 2019 at 03:10
Version:
8.8.x-dev
» 8.9.x-dev
Drupal 8.8.0-alpha1
will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the
Drupal 8 and 9 minor version schedule
and the
Allowed changes during the Drupal 8 and 9 release cycles
or
to post comments
Comment
#10
5 September 2019 at 03:10
Version:
8.9.x-dev
» 9.1.x-dev
Drupal 8.9.0-beta1
was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the
Drupal 8 and 9 minor version schedule
and the
Allowed changes during the Drupal 8 and 9 release cycles
or
to post comments
Comment
#11
5 September 2019 at 03:10
Version:
9.1.x-dev
» 9.2.x-dev
Drupal 9.1.0-alpha1
will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the
Drupal 9 minor version schedule
and the
Allowed changes during the Drupal 9 release cycle
or
to post comments
Comment
#12
5 September 2019 at 03:10
Version:
9.2.x-dev
» 9.3.x-dev
Drupal 9.2.0-alpha1
will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the
Drupal core minor version schedule
and the
Allowed changes during the Drupal core release cycle
or
to post comments
Comment
#13
5 September 2019 at 03:10
Version:
9.3.x-dev
» 9.4.x-dev
Drupal 9.3.0-rc1
was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the
Drupal core minor version schedule
and the
Allowed changes during the Drupal core release cycle
or
to post comments
Comment
#14
5 September 2019 at 03:10
Version:
9.4.x-dev
» 9.5.x-dev
Drupal 9.4.0-alpha1
was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the
Drupal core minor version schedule
and the
Allowed changes during the Drupal core release cycle
or
to post comments
Comment
#15
5 September 2019 at 03:10
Version:
9.5.x-dev
» 10.1.x-dev
Drupal 9.5.0-beta2
and
Drupal 10.0.0-beta2
were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the
Drupal core minor version schedule
and the
Allowed changes during the Drupal core release cycle
or
to post comments
Comment
#16
5 September 2019 at 03:10
Version:
10.1.x-dev
» 11.x-dev
Drupal core is moving towards using a “main” branch.
As an interim step, a new
11.x
branch has been opened
, as Drupal.org infrastructure cannot currently fully support a branch named
main
. New developments and disruptive changes should now be targeted for the
11.x
branch, which currently accepts only minor-version allowed changes. For more information, see the
Drupal core minor version schedule
and the
Allowed changes during the Drupal core release cycle
or
to post comments
Comment
#17
acbramley
commented
21 August 2023 at 09:18
Issue tags:
Bug Smash Initiative
, +
Needs tests
, +
Needs reroll
Looks like this still needs fixing, but most likely needs a reroll, definitely needs tests, and we should see if the other methods have corresponding issues.
or
to post comments
Comment
#18
akashkumar07
commented
22 August 2023 at 07:28
Status
File
Size
new
2954725-18.patch
442 bytes
Adding a reroll of #6.
or
to post comments
Comment
#19
vsujeetkumar
commented
24 August 2023 at 07:59
Status:
Needs work
» Needs review
Status
File
Size
new
2954725-19.patch
1.28 KB
new
interdiff_18-19.txt
729 bytes
Fixing the failed test case, Please have a look.
or
to post comments
Comment
#20
acbramley
commented
24 August 2023 at 22:41
Status:
Needs review
» Needs work
Issue tags:
Needs reroll
Looks good, but we should also have tests around this (core is notorious for setting string values when updating int fields via the UI).
Also need to action
#8
or
to post comments
Comment
#21
quietone
commented
6 November 2024 at 05:28
Issue tags:
DX
DX (Developer Experience)
Changing to the DX special tag defined on
Issue tags -- special tags
or
to post comments
Comment
#22
6 November 2025 at 19:31
dcam
made their first commit to this issue’s fork.
or
to post comments
Comment
#23
6 November 2025 at 19:34
dcam
opened
merge request !13712
or
to post comments
Comment
#24
dcam
commented
6 November 2025 at 20:16
Issue summary:
View changes
Status:
Needs work
» Needs review
Issue tags:
Needs tests
I converted #19 to an MR and added a Kernel test.
or
to post comments
Comment
#25
dcam
commented
6 November 2025 at 20:17
5 files were hidden/shown/deleted
Status
File
Size
hidden
2954725-2.patch
436 bytes
hidden
2954725-6.patch
442 bytes
hidden
2954725-18.patch
442 bytes
hidden
2954725-19.patch
1.28 KB
hidden
interdiff_18-19.txt
729 bytes
or
to post comments
Comment
#26
smustgrave
commented
28 December 2025 at 19:17
Status:
Needs review
» Needs work
Believe #8 still needs to be addressed.
or
to post comments
Comment
#27
dcam
commented
28 December 2025 at 23:56
Issue summary:
View changes
Status:
Needs work
» Needs review
I changed the
UserSession->access
type and updated the proposed resolution accordingly.
I searched for instantiations of
User
and
UserSession
. I didn't find any
User
instantiations. None of the
UserSession
instantiations set the
access
value. No action was taken.
or
to post comments
Comment
#28
smustgrave
commented
29 December 2025 at 18:58
Status:
Needs review
» Reviewed & tested by the community
Feedback appears to be addressed.
or
to post comments
Comment
#29
29 December 2025 at 18:58
Version:
11.x-dev
» main
Drupal core is now using the
main
branch as the primary development branch. New developments and disruptive changes should now be targeted to the
main
branch.
Read more in the announcement
or
to post comments
Comment
#30
needs-review-queue-bot
commented
31 January 2026 at 05:56
Status:
Reviewed & tested by the community
» Needs work
Status
File
Size
new
2954725-nr-bot_wcz9k384.txt
1.06 KB
The
Needs Review Queue Bot
tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the
Drupal Contributor Guide
to find step-by-step guides for working with issues.
or
to post comments
Comment
#31
dcam
commented
31 January 2026 at 14:56
Status:
Needs work
» Reviewed & tested by the community
Post-bot-rebellion rebase
or
to post comments
Comment
#32
dcam
commented
6 February 2026 at 19:59
There was a merge conflict in
core/modules/user/tests/src/Kernel/UserEntityTest.php
. I rebased the MR.
or
to post comments
Comment
#33
dcam
commented
17 February 2026 at 05:26
Had to rebase due to a deprecation test removal in
core/modules/user/tests/src/Kernel/UserEntityTest.php
or
to post comments
Comment
#34
dcam
commented
3 March 2026 at 17:53
This needed a rebase due to the removal of migrate_drupal.
or
to post comments
Comment
#35
godotislate
he/him
commented
16 March 2026 at 21:00
Status:
Reviewed & tested by the community
» Needs work
AccountProxy and UserSession implement
getLastAccessedTime()
as well, so presumably they need int casts on the return value?
or
to post comments
Comment
#36
acbramley
commented
16 March 2026 at 23:10
Confirming at least UserSession needs the cast -
\Drupal\user\Authentication\Provider\Cookie::getUserFromSession
creates a UserSesssion with values directly from the database. All of the timestamp fields are strings at this point. The UserSession constructor blindly sets these values on its properties.
I think AccountProxy is fine since it just does
$this->getAccount()->getLastAccessedTime()
so the other casts will be hit there.
or
to post comments
Comment
#37
acbramley
commented
16 March 2026 at 23:13
Status:
Needs work
» Needs review
or
to post comments
Comment
#38
dcam
commented
26 March 2026 at 19:09
Status:
Needs review
» Needs work
The line being changed in the User entity class was changed today by
#3574012: Add a getFieldValue() method to bypass typed data overhead for specific use cases
. The bug probably needs to be re-verified and the code has to be updated if it still exists.
or
to post comments
Comment
#39
acbramley
commented
26 March 2026 at 23:37
Status:
Needs work
» Needs review
or
to post comments
Comment
#40
smustgrave
commented
27 March 2026 at 15:00
Status:
Needs review
» Reviewed & tested by the community
Believe feedback for this one has been addressed.
Thanks!
or
to post comments
Comment
#41
20 April 2026 at 21:54
godotislate
closed
merge request !13712
or
to post comments
Comment
#42
20 April 2026 at 21:54
godotislate
committed
c62d3799
on
main
fix: #2954725 AccountInterface::getLastAccessedTime() implementors...
or
to post comments
Comment
#43
20 April 2026 at 21:54
godotislate
committed
dd785268
on
11.x
fix: #2954725 AccountInterface::getLastAccessedTime() implementors...
or
to post comments
Comment
#44
godotislate
he/him
commented
20 April 2026 at 21:56
Version:
main
» 11.x-dev
Status:
Reviewed & tested by the community
» Fixed
Committed and pushed
c62d379
to main.
There were merge conflicts against 11.x in the test classes, because of deprecation test methods that were removed in main. I manually resolved and committed
dd78526
and pushed to 11.x. Thanks!
or
to post comments
Comment
#45
20 April 2026 at 21:56
Now that this issue is closed,
review the
contribution record
As a contributor, attribute any organization that helped you, or if you volunteered your own time.
Maintainers, credit people who helped resolve this issue.
or
to post comments
Comment
#46
godotislate
he/him
commented
20 April 2026 at 22:19
Status:
Fixed
» Patch (to be ported)
There was this test failure on 11.x
Drupal\Tests\user\Kernel\Migrate\d6\MigrateUserTest::testUser
Failed asserting that 1543973668 is identical to '1543973668'.
core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserTest.php:108
so I reverted (commit 34e8746cc05c1404dcb1939cf7d80f98cbc42e3)
Set to Patch to be ported, will need an 11.x MR.
or
to post comments
Comment
#47
20 April 2026 at 22:21
godotislate
committed
34e8746c
on
11.x
Revert "fix: #2954725 AccountInterface::getLastAccessedTime()...
or
to post comments
Contribution record
Add child issue
clone issue
Related issues
Referenced by
#2952797: Email confirmation not created on first user login
Infrastructure management for Drupal.org provided by
Need a Drupal 7 extended support partner? Consider Tag1.
News items
News
Planet Drupal
Social media
Sign up for Drupal news
Security advisories
Jobs
Our community
Community
Services
Training
Hosting
Contributor guide
Groups & meetups
DrupalCon
Code of conduct
Documentation
Documentation
Drupal Guide
Drupal User Guide
Developer docs
API.Drupal.org
Drupal code base
Download & Extend
Drupal core
Modules
Themes
Distributions
Governance of community
About
Web accessibility
Drupal Association
About Drupal.org
Drupal is a
registered trademark
of
Dries Buytaert