Respect DB column defaults over attribute :foo, default: X overrides#358
Merged
OdenTakashi merged 2 commits intoJul 15, 2026
Merged
Conversation
`Model#column_defaults` reflects attribute overrides declared with `attribute :foo, default: X`, so annotations previously showed the overridden Ruby value instead of the actual DB default. Derive defaults from `columns_hash` and typecast via the schema-level cast type so annotations mirror `db/schema.rb`.
Deserializing `column.default` directly via the schema cast type loses model-level type decorations such as `TimeZoneConverter`, so datetime defaults previously rendered as `Tue, 04 Jul 2023 12:34:56.000000000 UTC +00:00` regressed to `2023-07-04 12:34:56 UTC` in annotations. Start from `Model#column_defaults` and only substitute the schema-derived value when it mismatches — a mismatch indicates an `attribute :foo, default: X` override.
OdenTakashi
approved these changes
Jul 15, 2026
Collaborator
There was a problem hiding this comment.
Thanks for the fix!
I agree with this change — Schema Information should reflect the DB schema default, not Ruby-side attribute overrides.
@drwl
One thing to keep in mind for release: this change will update existing annotations for models that override DB defaults with attribute. For example:
# DB default: "hello world!"
attribute :message, :string, default: "overridden by the model"Before:
# message :string default("overridden by the model")After:
# message :string default("hello world!")Columns without a database default are unaffected, and datetime defaults that are not overridden should keep their existing display format.
This might be a useful note for the release notes so users understand why their existing annotations might change after upgrading.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Model#column_defaultsreflects attribute overrides declared withattribute :foo, default: X, so annotations previously showed the overridden Ruby value instead of the actual DB default. Derive defaults fromcolumns_hashand typecast via the schema-level cast type so annotations mirrordb/schema.rb.