Skip to content

fix: [#706] Setting timezone in MySQL DSN (e.g., Asia/Shanghai) causes “invalid DSN” error#51

Merged
hwbrzzl merged 1 commit intomasterfrom
bowen/#706
Jun 14, 2025
Merged

fix: [#706] Setting timezone in MySQL DSN (e.g., Asia/Shanghai) causes “invalid DSN” error#51
hwbrzzl merged 1 commit intomasterfrom
bowen/#706

Conversation

@hwbrzzl
Copy link
Copy Markdown
Contributor

@hwbrzzl hwbrzzl commented Jun 14, 2025

📑 Description

Closes goravel/goravel#706

This pull request refines the handling of timezones in the configuration logic by removing hardcoded defaults and introducing a fallback mechanism to use the application's timezone when a database connection-specific timezone is not provided. Additionally, it updates the corresponding tests to ensure this behavior is properly validated.

Configuration Updates:

  • Removed the hardcoded "timezone": "UTC" from the example configuration in README.md.
  • Updated fillDefault in config.go to set the timezone dynamically. If no database connection-specific timezone is provided, it falls back to the application's timezone (app.timezone) with a default of "UTC".

Testing Enhancements:

  • Added a new test case in config_test.go to verify the fallback mechanism for the timezone when app.timezone is used.

✅ Checks

  • Added test cases for my code

@hwbrzzl hwbrzzl requested review from a team and Copilot June 14, 2025 10:28
Copy link
Copy Markdown
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 refines the timezone handling in the database configuration by removing a hardcoded default and introducing a fallback to the application's timezone when a connection-specific timezone is not provided. Key changes include:

  • Addition of a new test case in config_test.go ("success with app.timezone") to verify the fallback mechanism.
  • Modification of fillDefault in config.go to use a fallback from "app.timezone" when the connection-specific timezone is empty.
  • Update of README.md to remove a hardcoded timezone default.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
config_test.go Added test case for verifying timezone fallback from "app.timezone".
config.go Added fallback logic for setting timezone dynamically in the fillDefault method.
README.md Removed the default "timezone" configuration value.

Comment thread config.go
Comment on lines +95 to +99
timezone := r.config.GetString(fmt.Sprintf("database.connections.%s.timezone", r.connection))
if timezone == "" {
timezone = r.config.GetString("app.timezone", "UTC")
}
fullConfig.Timezone = timezone
Copy link

Copilot AI Jun 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider refactoring the fallback logic by directly using a GetString call that allows specifying a default value (e.g., r.config.GetString(key, default)) to improve readability and reduce redundant calls.

Suggested change
timezone := r.config.GetString(fmt.Sprintf("database.connections.%s.timezone", r.connection))
if timezone == "" {
timezone = r.config.GetString("app.timezone", "UTC")
}
fullConfig.Timezone = timezone
fullConfig.Timezone = r.config.GetString(fmt.Sprintf("database.connections.%s.timezone", r.connection), r.config.GetString("app.timezone", "UTC"))

Copilot uses AI. Check for mistakes.
@hwbrzzl hwbrzzl merged commit ab2119a into master Jun 14, 2025
5 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#706 branch September 6, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting timezone in MySQL DSN (e.g., Asia/Shanghai) causes “invalid DSN” error

2 participants