Skip to content

Conversation

@sampart
Copy link

@sampart sampart commented Dec 3, 2025

The change

data.fetch("expiration_time_millis", 0) will default to 0 only if the key is not present. If the key is present but the associated value is nil, then prior to this change the code would raise as follows:

NoMethodError (undefined method `/' for nil:NilClass

          expires_at:    data.fetch("expiration_time_millis", 0) / 1000
                                                                 ^):

This commit updates the code to default to 0 if the key is not found or if the value is nil.

With the existing token stores, this situation may not arise, but it's a particular issue when using a custom token store where values could be nil, like a database.

Testing

Since the existing tests don't cover the existing fallback, I've not added to them here either.

I've tested this change manually locally by modifying my copy of the gem in a test project.

Changelog

https://github.com/googleapis/google-auth-library-ruby/blob/main/.github/CONTRIBUTING.md mentions updating the CHANGELOG. However, CHANGELOG updates now appear to be an automated process so I've left this alone.

@sampart sampart requested a review from a team as a code owner December 3, 2025 12:49
@sampart sampart changed the title Don't raise an error if expiration_time_millis is nil; fall back to 0 Fix: Don't raise an error if expiration_time_millis is nil; fall back to 0 Dec 3, 2025
…ck to 0

`data.fetch("expiration_time_millis", 0)` will default to 0 only if the key is not present. If the key is present but the associated value is nil, then prior to this change the code would raise as follows:

```
NoMethodError (undefined method `/' for nil:NilClass

          expires_at:    data.fetch("expiration_time_millis", 0) / 1000
                                                                 ^):

```

This commit updates the code to default to 0 if the key is not found or if the value is nil.

With the existing token stores, this situation may not arise, but it's a particular issue when using a custom token store where values could be nil, like a database.
@sampart sampart force-pushed the expires-at-handle-nil branch from 3d80798 to 3f1709d Compare December 3, 2025 14:07
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.

1 participant