Skip to content

Rails 6.1: Coerce schema cache test to handle Time marshal in ruby 2.5 and 2.6 #916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mgrunberg
Copy link
Contributor

@mgrunberg mgrunberg commented Apr 27, 2021

This PR fixes:

ActiveRecord::ConnectionAdapters::SchemaCacheTest#test_marshal_dump_and_load_via_disk:
ArgumentError: year too big to marshal: 1753 UTC
ActiveRecord::ConnectionAdapters::SchemaCacheTest#test_marshal_dump_and_load_with_gzip:
ArgumentError: year too big to marshal: 1753 UTC

Those errors only exists in ruby 2.5 and 2.6 runs

Context

Rails 6.1 adds support for marshal as a schema cache serialization strategy (rails/rails@9a356fc)

Ruby 2.5 and Ruby 2.6 have a bug that prevents them to marshal Time instances before 1900 (see https://bugs.ruby-lang.org/issues/15160). The issue is not present on 2.7. Found the link looking at rails/rails#41075.

sst_datatypes table has a datetime column with default 1753-01-01T00:00:00.123. The table is created here https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/main/test/schema/datatypes/2012.sql#L27.

Possible solutions

  1. update 2012.sql and change default to something else.

That file has been around for a while. I can't tell why 1753-01-01T00:00:00.123 was picked. For example, I can't tell if it's covering some specific scenario.

  1. coerce the test

change the default value just for the failing test and rubies.

  1. cast default value to something different than Time

Haven't thought/investigate this path but felt that would lead to issues.

I choose the second option

@mgrunberg mgrunberg changed the title Rails 6.1: Coerce test related to schema cache time marshal Rails 6.1: Coerce schema cache test to handle Time marshal in ruby 2.5 and 2.6 Apr 27, 2021
@mgrunberg mgrunberg force-pushed the issues/yellowspot/rails-6-1/coerce-schema-cache-time-marshal branch from f5189ee to 6e1b629 Compare April 27, 2021 12:47
@mgrunberg mgrunberg marked this pull request as ready for review April 27, 2021 13:31
@aidanharan
Copy link
Contributor

I'd be inclined just to change the year to something 1900+. Can't see anything in the original commit to indicate why 1753 was picked 3fb340c

@mgrunberg
Copy link
Contributor Author

mgrunberg commented Apr 27, 2021

I'm starting to think that '1753-01-01T00:00:00.123' was picked because is the minimum valid value for datetime columns.

According to docs (https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-ver15) datetime columns goes from 1753-01-01 00:00:00 to 9999-12-31 23:59:59.997

2012.sql has a smalldatetime with 1900-01-01 00:00:00, which is the min value.

If this is the case, keeping 1753-01-01T00:00:00.123 feels correct.

@aidanharan
Copy link
Contributor

Considering that Ruby 2.5 had already reached EOL and Ruby 2.6 reaches EOL in 2022-03-31 (https://www.ruby-lang.org/en/downloads/branches/) I think it's fine to coerce the tests as you've done.

@wpolicarpo wpolicarpo merged commit 6855ef8 into rails-sqlserver:main Apr 28, 2021
@mgrunberg mgrunberg deleted the issues/yellowspot/rails-6-1/coerce-schema-cache-time-marshal branch January 3, 2022 17:31
lavika pushed a commit to lavika/activerecord-sqlserver-adapter that referenced this pull request Sep 26, 2023
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.

3 participants