-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
WIP: Use default :enum value from database column's one #23190
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This is not the right fix. Read e991c7b I will check this out. |
hmm, basically sqlite (in this example) returns string zero as string for 'PRAGMA table_info(books) with type integer and we're overwriting resulting So basically we should add type_cast somewhere, but I'm not sure where exactly where.
and type_cast actually happens in Attribute#value. So the questions are:
|
So I think that basically type_cast should be moved to define_default_attribute or somewhere like that. I've pushed rails with this fix, please see the updated PR (count it as RFC, no commit message changes/etc was made). There are three test failures:
but I'm not sure if this tests are correct. If this fix looks proper -- I'll try to investigate if there is any more suitable place for type_cast and remove excessive type_casts further. |
Aha, these tests are for before_type_cast values.
Please advise, I'm lost. |
@@ -251,7 +251,7 @@ def define_default_attribute(name, value, type, from_user:) | |||
_default_attributes[name], | |||
) | |||
else | |||
default_attribute = Attribute.from_database(name, value, type) | |||
default_attribute = Attribute.from_database(name, type.cast(value), type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attributes should never be cast on construction.
Reverts e991c7b and adds the test
Fixes #23187