Skip to content

Conversation

@ysinghc
Copy link
Contributor

@ysinghc ysinghc commented Feb 11, 2026

Summary

What does this PR do?

This PR fixes a MySQL datetime error that occurs when creating GitHub connections with Personal Access Tokens (PATs). The fix modifies the token_expires_at and refresh_token_expires_at columns in the _tool_github_connections table to be nullable.

The Problem:

  • MySQL rejects '0000-00-00' datetime values with error: Error 1292 (22007): Incorrect datetime value: '0000-00-00' for column 'token_expires_at'
  • PAT-based GitHub connections don't have OAuth-style token expiration, so these fields should be NULL
  • The database columns were not nullable, causing connection creation to fail

The Solution:

  • Added a database migration script to alter token_expires_at and refresh_token_expires_at columns to be nullable (*time.Time)
  • This allows PAT connections to store NULL values while OAuth connections can still store actual expiration timestamps

Does this close any open issues?

Closes #8693

Screenshots

Other Information

Copilot AI review requested due to automatic review settings February 11, 2026 03:19
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 11, 2026
@dosubot dosubot bot added component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug priority/high This issue is very important severity/p1 This bug affects functionality or significantly affect ux labels Feb 11, 2026
Copy link
Contributor

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 PR fixes a MySQL datetime error that occurs when creating GitHub connections with Personal Access Tokens (PATs). The issue arose because MySQL rejects '0000-00-00' datetime values, which were being used for PAT connections that don't have OAuth-style token expiration. The fix makes the token_expires_at and refresh_token_expires_at columns nullable, allowing PAT connections to store NULL values while OAuth connections can still store actual expiration timestamps.

Changes:

  • Modified TokenExpiresAt and RefreshTokenExpiresAt fields from time.Time to *time.Time in the GithubConnection model
  • Added nil check in token refresh logic to prevent attempting token refresh for PAT connections
  • Updated all test files to use pointer values for token expiration timestamps
  • Created database migration to alter columns to be nullable

Reviewed changes

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

Show a summary per file
File Description
backend/plugins/github/models/connection.go Changed TokenExpiresAt and RefreshTokenExpiresAt fields to pointers (*time.Time) and updated UpdateToken signature
backend/plugins/github/models/migrationscripts/20260211_modify_connection_token_expires_at_to_nullable.go Added new migration script to make token expiration fields nullable in database
backend/plugins/github/models/migrationscripts/register.go Registered the new migration script
backend/plugins/github/token/token_provider.go Added nil check for TokenExpiresAt before dereferencing, and updated to pass pointers to UpdateToken
backend/plugins/github/token/token_provider_test.go Updated tests to create expiry time variables and pass pointers
backend/plugins/github/token/round_tripper_test.go Updated test to create expiry time variable and pass pointer
Comments suppressed due to low confidence (1)

backend/plugins/github/token/token_provider_test.go:75

  • The test cases in this file don't include a scenario where TokenExpiresAt is nil, which represents a PAT (Personal Access Token) connection without OAuth-style token expiration. Consider adding a test case like:
// Nil TokenExpiresAt (PAT token without expiration)
tp.conn.TokenExpiresAt = nil
assert.False(t, tp.needsRefresh())

This would ensure the nil check in token_provider.go (line 87-89) works correctly for PAT connections.

func TestNeedsRefresh(t *testing.T) {
	tp := &TokenProvider{
		conn: &models.GithubConnection{
			GithubConn: models.GithubConn{
				RefreshToken: "refresh_token",
			},
		},
	}

	// Not expired, outside buffer
	expiry1 := time.Now().Add(10 * time.Minute)
	tp.conn.TokenExpiresAt = &expiry1
	assert.False(t, tp.needsRefresh())

	// Inside buffer
	expiry2 := time.Now().Add(1 * time.Minute)
	tp.conn.TokenExpiresAt = &expiry2
	assert.True(t, tp.needsRefresh())

	// Expired
	expiry3 := time.Now().Add(-1 * time.Minute)
	tp.conn.TokenExpiresAt = &expiry3
	assert.True(t, tp.needsRefresh())

	// No refresh token
	tp.conn.RefreshToken = ""
	assert.False(t, tp.needsRefresh())
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@klesh klesh left a comment

Choose a reason for hiding this comment

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

LGTM! Good work.

@klesh klesh merged commit 32eafc8 into apache:main Feb 12, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug priority/high This issue is very important severity/p1 This bug affects functionality or significantly affect ux size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Onboarding] GitHub token on v1.0.3-beta9

2 participants