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
Add a Date decoder to the pg adapter #51483
Add a Date decoder to the pg adapter #51483
Conversation
ea64815
to
92f7d37
Compare
Could you add a test? Particularly one that make sure it will be parsed correctly when using a model. |
92f7d37
to
fc9871d
Compare
Sorry, I was away last week. @byroot while looking for a place to write the test, I found those. Do you think they are sufficient? I've also added a test for the decoding of the date : https://github.com/rails/rails/pull/51483/files#diff-f3109c7be3eb7602954054584dc86a6edc790b68dee0fc36654b427b8b11febfR43-R47 |
at the connection level Fix rails#51448 Type cast columns of type `date` to ruby `Date` when running a raw query through `ActiveRecord::Base.connection.select_all`.
fc9871d
to
2c88c80
Compare
On the one hand, this is definitely an improvement 👍 On the other hand, it's almost certainly a breaking change. We had some code that broke from this, where we were manually doing Is it worth making this an opt in? I am happy to make a PR if so. @byroot @JoeDupuis |
It probably should have it's config and |
Shoot 😕 I can write a PR later today. |
@ghiculescu Mind if I do it? That'll teach me about the config/default system. I'll keep that in mind for the next PR 😅 |
Go ahead @JoeDupuis ! I can review if you like |
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
@ghiculescu I opened the PR: #51763 |
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
to toggle automatic decoding of dates column with the PostgresqlAdapter. PR rails#51483 is a breaking change and should have been gated behind a config.
Fix #51448
Add a Date decoder to the pg adapter to type cast dates at the connection level
This would type cast columns of type
date
to rubyDate
when running a raw query throughActiveRecord::Base.connection.select_all
.Before:
After:
While I don't think we'd want to to set a type cast expectation at this level (not all adapters have dates), this would brings the PG adapter to parity (for dates) with the Mysql2 adapter.
We already convert timestamp, it would makes sense to also convert dates.
I wasn't sure if I should add a test. I am thinking that a test sets an expectation about type casting at the adapter level.
This changes a public API, albeit a pretty low level one, but it seems like we don't test the other types either. I removed timestamps + float/numeric and all tests still pass.
I added a message in the changelog entry to make sure it doesn't burn anyone.
Unsure if we should merge this. Impact radius is large, but after digging into it and running the tests, it looks pretty benign.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]