Skip to content
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

"Assign auto populated columns on Active Record object creation", breaks the returning of id on insert #2380

Open
andynu opened this issue Mar 28, 2024 · 1 comment · May be fixed by #2381

Comments

@andynu
Copy link
Contributor

andynu commented Mar 28, 2024

Overview

The rails commit [1] changes how values are returned from insert statements. The worthy goal is to use the RETURNING statement in postgres to set all the database generated attribute values as a direct result of the insert statement. Oracle supports the RETURNING statement too and may ultimately benefit from this change! As part of this change, the ActiveRecord::Persistence#_create_record now looks for a set of returning_columns instead of assuming that the primary key is being returned.

The challenge with this in the oracle adapter is the way this returning_columns list is built via
ActiveRecord::ConnectionAdapters::Column#auto_incremented_by_db? which defaults to a literal false. (or slightly higher up the callstack connection.return_value_after_insert?(c) where c is a Column)

The oracle enhanced adapter does not appear to have knowledge about if a column is a primary key or not on the Column record itself (at least not on that record, or within the sql_type_metadata). It is unclear to me how best to identify which columns are the primary key, and thus should be included in the returning_columns collection.

[1] rails/rails@3421e89

Steps to reproduce

You can see the barest implementation of the parameters for the rails change, and the problem in the tests here:
andynu@336d04b

Expected behavior

insert should return the id of the new record

Actual behavior

insert returns nil

System configuration

Rails version: not quite 7.1.0 - 3421e892afa532a254e54379ac2ce9bef138cf3f

Oracle enhanced adapter version: a little ways off master, 4707dfa

Ruby version: 3.2.2

Oracle Database version: 23.0.0

@andynu
Copy link
Contributor Author

andynu commented Mar 29, 2024

This may have been corrected on the rails side.

rails/rails#50783

This fix has not been released yet, and will probably be part of Rails 7.2.0.

But it was back ported to 7.1.0 here: rails/rails@221e609 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant