Skip to content

Support composite primary keys in write_lobs#2697

Merged
yahonda merged 1 commit into
rsim:masterfrom
yahonda:fix-2694-write-lobs-cpk
May 5, 2026
Merged

Support composite primary keys in write_lobs#2697
yahonda merged 1 commit into
rsim:masterfrom
yahonda:fix-2694-write-lobs-cpk

Conversation

@yahonda

@yahonda yahonda commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Build the SELECT ... FOR UPDATE predicate in write_lobs from each
primary-key component, so CpkModel.create! with a CLOB or BLOB
column works when the post-save LOB rewrite path runs (the case the
TODO from #2693 flagged). The single-PK SQL stays byte-identical via
Array(klass.primary_key), so existing scalar-PK behavior is unchanged.

Adds cpk_docs (CPK + CLOB + BLOB) coverage to
composite_primary_key_spec.rb, exercising both the default
prepared_statements: true path and the prepared_statements: false
post-save rewrite path for both CLOB and BLOB.

Closes #2694.

Related

The insert_fixture LOB call site is broken on this Ruby /
ActiveRecord-main combination by an unrelated ORA-01002 (the
SELECT ... FOR UPDATE cursor fetch outside a transaction). It
reproduces with a single-column primary key as well, so the fix lives
in #2698 (closes #2696). Once that lands, a CPK + LOB insert_fixture
test can be added on top of this PR's cpk_docs setup.

Test plan

  • bundle exec rubocop
  • bundle exec rspec spec/active_record/connection_adapters/oracle_enhanced/composite_primary_key_spec.rb (42/42)
  • ORACLE_ENHANCED_PREPARED_STATEMENTS_FALSE=1 bundle exec rspec spec/active_record/connection_adapters/oracle_enhanced/composite_primary_key_spec.rb (42/42)
  • bundle exec rspec spec/active_record/oracle_enhanced/type/text_spec.rb (21/21, single-PK LOB regression)

Build the SELECT ... FOR UPDATE predicate from each PK component so
CpkModel.create! with a CLOB or BLOB column works when the post-save
LOB rewrite path runs (i.e. with prepared_statements: false). The
single-PK shape stays byte-identical via Array(klass.primary_key).

Closes rsim#2694.
@yahonda yahonda force-pushed the fix-2694-write-lobs-cpk branch from 2274349 to d594e33 Compare May 5, 2026 14:42
@yahonda yahonda merged commit c5e1a31 into rsim:master May 5, 2026
24 checks passed
@yahonda yahonda deleted the fix-2694-write-lobs-cpk branch May 5, 2026 22:09
yahonda added a commit that referenced this pull request May 5, 2026
PR #2697 added the cpk_docs setup and CPK + LOB create! coverage but
deferred insert_fixture, which was failing for an unrelated reason
later fixed by #2698 (transaction wrap). Both fixes are now on master,
so add the missing case the umbrella issue listed.
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.

insert_fixture against a LOB column raises ORA-01002 (single-PK and CPK) Composite primary key support for write_lobs (CLOB/BLOB on CPK models)

1 participant