Skip to content

Mutate readonly LOB attributes in place in the CLOB/NCLOB specs - #2973

Merged
yahonda merged 1 commit into
rsim:masterfrom
yahonda:fix-clob-attr-readonly-specs
Oct 23, 2026
Merged

yahonda merged 1 commit into
rsim:masterfrom
yahonda:fix-clob-attr-readonly-specs

Conversation

@yahonda

@yahonda yahonda commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Six examples in text_spec.rb and national_character_text_spec.rb fail on current Rails main with ActiveRecord::ReadonlyAttributeError:

  • should respect attr_readonly setting for CLOB/NCLOB column (also the prepared_statements disabled variant)
  • should work for serialized readonly CLOB/NCLOB columns

rails/rails@0f6c0a05e2 ("Inline _write_attribute in generated writer methods", 2026-10-19) makes assigning to an attr_readonly attribute on a persisted record raise by default, and deprecates config.active_record.raise_on_assign_to_attr_readonly. These specs assigned a new value to the readonly column, so they failed before reaching save.

The specs check that the adapter's LOB writing does not write a readonly column (record_changed_lobs in lob.rb skips readonly attributes). They now change the value in place (String#replace, or a key added to the serialized Hash) instead of assigning it. Each spec first checks that assignment raises ActiveRecord::ReadonlyAttributeError, which documents why the value is changed in place and will catch a future change in Rails. It then checks will_save_change_to_comments? is true and keeps asserting that the reloaded value is unchanged. The serialized specs start from {} instead of nil, because a nil value cannot be changed in place.

No library code changes.

Testing

CRuby 4.0.7, Oracle Database 23.26, Rails main fa15ed655a. Both spec files: 45 examples, 0 failures, with and without ORACLE_ENHANCED_PREPARED_STATEMENTS_FALSE=1. Before this change, 6 of them failed on master 659e906.

As a check, I removed the readonly filter from record_changed_lobs and ran the specs again. The two prepared_statements disabled examples then fail. With prepared statements on, the readonly examples pass either way.

🤖 Generated with Claude Code

rails/rails@0f6c0a05e2 makes assignment to an `attr_readonly` attribute
on a persisted record raise ActiveRecord::ReadonlyAttributeError by
default (and deprecates `raise_on_assign_to_attr_readonly`), so the
specs that assigned a new value to a readonly CLOB/NCLOB column failed
before reaching save.

Change the value in place instead, check that the change is detected,
and keep asserting that save does not write it. Also assert that
assigning a new value raises, which documents why the specs mutate in
place and catches a future change in Rails behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yahonda
yahonda force-pushed the fix-clob-attr-readonly-specs branch from 73d9ffa to 3a0fd2f Compare October 23, 2026 08:59
@yahonda
yahonda merged commit d203040 into rsim:master Oct 23, 2026
12 checks passed
@yahonda
yahonda deleted the fix-clob-attr-readonly-specs branch October 23, 2026 09:18
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.

1 participant