Repository navigation
Render nullable boolean columns with default value of false as not optional on rails 8.1 (like previous versions of rails did) - #36
Merged
ElMassimo merged 3 commits intoJul 3, 2026
Conversation
To give us some nullable boolean columns with defaults to test against rails 8.1 behaviour.
Rails 8.1 changes how default values are represented, and testing against it with the boolean values we added in the previous commit should trigger an error.
On rails 8.1 default values are type cast rather than being returned as db strings which means a default value of false for a boolean column now comes through as the boolean `false` rather than the string `"false"`. This means when we check if a nullable boolean column with a default value of `false` is optional we say it is optional on rails 8.1 because `false` fails the `!column.default` check whereas on rails 8.0 or lower we say it is not optional because `"false"` passes the `!column.default` check. This fixes that by using `column.default.nil?` instead.
false as not optional on rails 8.1 (like previous versions of rails did)
Owner
|
Looks good, thanks Murray! |
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.
Description 📖
This pull request fixes a change in behaviour when running on rails 8.1 in how we decide if a nullable boolean column with a default value of false is optional or not when rendering the types from it. In rails 8.0 or lower we think such a column is not optional, in rails 8.1 with no other changes we think it is optional.
Background 📜
This was happening because in rails 8.1 default values in the column objects are now typecast to return the ruby object they'd represent, rather than a raw string from the db. So, a boolean false is now
falsenot"false". Deciding if an attribute for a should be optional or not in the rendered types relies on checking if the column is nullable and if it has a default value set. The check used!column.defaultfor the default values, and now that false is the booleanfalseinstead of the string"false"we get different behaviour after upgrading to rails 8.1.The Fix 🔨
By changing
!column.defaulttocolumn.default.nil?we preserve the existing behaviour and still letfalsedefault values on boolean columns through.Screenshots 📷
N/A
Notes
I think what's in the commits is the minimum change needed, but locally I had to make many changes to Gemfile, Gemfile.lock, package.json, ppm-lock.yaml to get things to work. I also couldn't get the specs to fail so while I'm confident the fix is the right one, they only way I proved this to myself was:
bundle exec rake types_from_serializers:generateplayground/vanillato 8.1bundle exec rake types_from_serializers:generatebundle exec rake types_from_serializers:generateAt no point would
rspecfrom the main folder fail. Trying to runrspecusing the rails 8.1 gemfile I added ingemfilesdidn't seem to do anything either. Let me know if we need more infrastructure changes to prove this out.