Skip to content

Deserialize auto populated columns on Active Record object creation #53436

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

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

baarde
Copy link
Contributor

@baarde baarde commented Oct 24, 2024

Motivation / Background

Fixes #53435

This Pull Request has been created because values returned from the databases need to be deserialized as they may use a different format, such as PostgreSQL bytea "hex" format.

Detail

This Pull Request replaces #write_from_user with #write_from_database when assigning the auto populated values returned by the database.

Additional information

I don't like the fact that we access @attributes directly, but #reload does it too and it's the simplest solution.

Alternatives considered:

  • Adding an ad-hoc _write_attribute_from_database method somewhere (ActiveRecord::AttributeMethods::Write?).
  • Deserializing the value using attributes_builder.types[column].deserialize(value).

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Values returned from the databases need to be deserialized as they may use a different format, such as PostgreSQL bytea "hex" format.

Fix rails#53435
@kamipo kamipo merged commit 0e3e0d1 into rails:main Oct 30, 2024
2 of 3 checks passed
kamipo added a commit that referenced this pull request Oct 30, 2024
Deserialize auto populated columns on Active Record object creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto populated columns are not properly deserialized on Active Record object creation
2 participants