Skip to content

Conversation

aibaq
Copy link

@aibaq aibaq commented Sep 16, 2025

Fixes #

Description of the Change

Django User's last_login field is nullable, so /o/token/ endpoint raises TypeError when last_login is null when using oidc

Снимок экрана 2025-09-16 в 13 05 42

This fix sets timezone.now() as a default value for auth_time

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • [o] documentation updated (not needed)
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS

@aibaq aibaq changed the title Fix TypeError at /s/auth/o/token/ Fix TypeError at /o/token/ Sep 16, 2025
Copy link

codecov bot commented Oct 3, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
oauth2_provider/oauth2_validators.py 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@dopry
Copy link
Member

dopry commented Oct 3, 2025

@aibaq this is a great start. to help me understand the issue a bit more, in what scenario did you encounter this issue? I would expect that a user would have logged in at least once by the time get_id_token_dictionary was called. I'd like to understand how this was occurring to both correct my expectations and ensure there isn't a bug somewhere else that is allow a token to be generated for a user that isn't authenticated. It also looks like there is a code path that is uncovered that will need to be tested.

@dopry dopry requested a review from Copilot October 3, 2025 16:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes a TypeError that occurs at the /o/token/ endpoint when using OIDC and the Django User's last_login field is null. The fix adds a null check for last_login and provides a fallback value using the current timestamp.

  • Added null safety check for request.user.last_login before accessing it
  • Set timezone.now().timestamp() as fallback when last_login is null
  • Added test case to verify the fix works with null last_login values

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
oauth2_provider/oauth2_validators.py Added null check for last_login and fallback to current timestamp
tests/test_oauth2_validators.py Added test setup to simulate user with null last_login
CHANGELOG.md Added entry for the TypeError fix
AUTHORS Added contributor name

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants