Skip to content

Get attribute values before type casting to fix enum attributes insert#3

Merged
sncalvo merged 2 commits into
mainfrom
fix/enum_values
Apr 21, 2026
Merged

Get attribute values before type casting to fix enum attributes insert#3
sncalvo merged 2 commits into
mainfrom
fix/enum_values

Conversation

@carlos-musetti
Copy link
Copy Markdown
Contributor

@carlos-musetti carlos-musetti commented Feb 18, 2026

I have a model with an enum.

Screenshot 2026-02-18 at 9 15 01 AM

When trying to insert records into this model, the INSERT INTO tuple would have the cast value (i.e. raw instead of 0), triggering an error since postgresql` expected the value before casting.

@sncalvo
Copy link
Copy Markdown
Member

sncalvo commented Feb 18, 2026

Can you make a spec to verify usage with enums? @carlos-musetti

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes staging inserts for ActiveRecord enum-backed columns by normalizing AR records into “database-ready” attribute values (instead of enum labels), and adds regression coverage across supported DB adapters.

Changes:

  • Add regression specs ensuring enum attributes are staged as underlying DB integers (AR objects, relations, and plain hashes).
  • Update StagingTable::Session record normalization to prefer attributes_for_database / read_attribute_for_database.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
spec/staging_table/enum_attributes_spec.rb Adds multi-adapter regression tests for enum value normalization through staging + transfer.
lib/staging_table/session.rb Changes normalization logic to extract database values for AR records (aimed at fixing enum inserts).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/staging_table/session.rb Outdated
Comment thread lib/staging_table/session.rb Outdated
Comment thread spec/staging_table/enum_attributes_spec.rb
@sncalvo sncalvo merged commit 909d6fd into main Apr 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants