Skip to content

Upgrade globalize to version 7.0 for Rails 7.2 support#153

Open
swamp09 wants to merge 1 commit intosolidusio-contrib:mainfrom
swamp09:upgrade_globalize_7.0
Open

Upgrade globalize to version 7.0 for Rails 7.2 support#153
swamp09 wants to merge 1 commit intosolidusio-contrib:mainfrom
swamp09:upgrade_globalize_7.0

Conversation

@swamp09
Copy link
Copy Markdown

@swamp09 swamp09 commented Jan 20, 2025

This PR updates the globalize dependency to ~> 7.0 to support Rails 7.2.
https://github.com/globalize/globalize/releases/tag/v7.0.0

swamp09 added a commit to swamp09/solidus that referenced this pull request Jan 20, 2025
This PR modifies the Persistable module in Solidus to check the Rails version using Rails.gem_version instead of inspecting the serialize method parameters. This change is necessary only when using Solidus Globalize, ensuring compatibility with Rails 7.2.

## Background
Solidus itself does not have any issues with the current implementation:

```
if method(:serialize).parameters.include?([:key, :type]) # Rails 7.1+
  serialize :preferences, type: Hash, coder: YAML
else
  serialize :preferences, Hash, coder: YAML
end
```

However, when using Solidus Globalize, which relies on globalize, an issue arises in Rails 7.2 due to globalize overriding the serialize method:

```
ArgumentError: wrong number of arguments (given 2, expected 1)
```

This occurs because the serialize method signature is modified by globalize, causing a mismatch when Solidus inspects its parameters.
For reference, see the globalize implementation here:
https://github.com/globalize/globalize/blob/main/lib/patches/active_record/rails7_2/serialization.rb

## Solution
To avoid conflicts, this PR replaces the method introspection with a Rails version check:
```
if Rails.gem_version >= Gem::Version.new('7.1')
  serialize :preferences, type: Hash, coder: YAML
else
  serialize :preferences, Hash, coder: YAML
end
```
This approach ensures compatibility while keeping Solidus independent from dependency-specific overrides.

This issue is currently blocking the CI of the following PR in the solidus_globalize repository:
solidusio-contrib/solidus_globalize#153
Fixing this in Solidus will help unblock that PR.
github-actions Bot pushed a commit to solidusio/solidus that referenced this pull request Jan 21, 2025
This PR modifies the Persistable module in Solidus to check the Rails version using Rails.gem_version instead of inspecting the serialize method parameters. This change is necessary only when using Solidus Globalize, ensuring compatibility with Rails 7.2.

## Background
Solidus itself does not have any issues with the current implementation:

```
if method(:serialize).parameters.include?([:key, :type]) # Rails 7.1+
  serialize :preferences, type: Hash, coder: YAML
else
  serialize :preferences, Hash, coder: YAML
end
```

However, when using Solidus Globalize, which relies on globalize, an issue arises in Rails 7.2 due to globalize overriding the serialize method:

```
ArgumentError: wrong number of arguments (given 2, expected 1)
```

This occurs because the serialize method signature is modified by globalize, causing a mismatch when Solidus inspects its parameters.
For reference, see the globalize implementation here:
https://github.com/globalize/globalize/blob/main/lib/patches/active_record/rails7_2/serialization.rb

## Solution
To avoid conflicts, this PR replaces the method introspection with a Rails version check:
```
if Rails.gem_version >= Gem::Version.new('7.1')
  serialize :preferences, type: Hash, coder: YAML
else
  serialize :preferences, Hash, coder: YAML
end
```
This approach ensures compatibility while keeping Solidus independent from dependency-specific overrides.

This issue is currently blocking the CI of the following PR in the solidus_globalize repository:
solidusio-contrib/solidus_globalize#153
Fixing this in Solidus will help unblock that PR.

(cherry picked from commit 2bcf076)
This PR updates the globalize dependency to ~> 7.0 to support Rails 7.2.
https://github.com/globalize/globalize/releases/tag/v7.0.0
@swamp09 swamp09 force-pushed the upgrade_globalize_7.0 branch from e3b6e89 to fb95f5f Compare February 13, 2025 06:57
@fthobe
Copy link
Copy Markdown

fthobe commented Mar 7, 2025

@jarednorman I saw you worked on globalize, is this obselete now or can we merge this?

@jarednorman
Copy link
Copy Markdown
Member

I don't know. I know there's some trickiness around supporting different versions of the globalize gem. I believe @harmonymjb was running into those issues.

@harmonymjb
Copy link
Copy Markdown

I think these content of commits that I added need to be removed with enforcing Globalize >= 7.

6db9f8e
c8caf17

They were added to allow support for Globalize 6 but in Globalize 7, it isn't needed.

I don't think this is related to the test failures here though, those seem to be related to these 2 commits:

solidusio/solidus@ce43cf9
solidusio/solidus@eaf4f5f

I suspect your PR ran it's tests against main between these 2 commits, causing the mainfest related failure.

@fthobe
Copy link
Copy Markdown

fthobe commented Mar 20, 2025

@harmonymjb @jarednorman Globalize is not maintained anymore. Maybe it's easier for all of us if we move to mobility. It's a relatively straightforward migration. https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize

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.

4 participants