Skip to content

Translate ORA-02290 to ActiveRecord::CheckViolation#2790

Merged
yahonda merged 1 commit into
rsim:masterfrom
yahonda:translate-check-violation
May 13, 2026
Merged

Translate ORA-02290 to ActiveRecord::CheckViolation#2790
yahonda merged 1 commit into
rsim:masterfrom
yahonda:translate-check-violation

Conversation

@yahonda

@yahonda yahonda commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Oracle raises ORA-02290 ("check constraint (…) violated") when an INSERT or UPDATE produces a row that fails a CHECK constraint. oracle-enhanced's translate_exception (oracle_enhanced_adapter.rb:1433-1452) had no entry for code 2290, so the error fell through to AbstractAdapter#translate_exception and surfaced as a generic ActiveRecord::StatementInvalid. Applications catching constraint violations could not distinguish a check failure from any other statement error.
  • Map ORA-02290 to ActiveRecord::CheckViolation alongside the existing constraint-violation mappings:
    • ORA-01400 → NotNullViolation
    • ORA-02290 → CheckViolation (this PR)
    • ORA-02291 / ORA-02292 → InvalidForeignKey
    • ORA-12899 → ValueTooLong
  • oracle-enhanced has supported add_check_constraint / t.check_constraint since Wire up CHECK constraint DSL: add_check_constraint, t.check_constraint, dump round-trip #2717; the missing exception mapping was the remaining gap on the CHECK-constraint surface. With this PR ActiveRecord::Base.connection.execute (and AR's create / update paths) emit the AR-portable CheckViolation for check-constraint violations on Oracle, matching the PostgreSQL / MySQL / SQLite3 contract.
  • Adds a direct integration assertion in the existing describe "check constraints" block of spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb: create a check constraint on test_products, attempt an INSERT that violates it, expect ActiveRecord::CheckViolation with a message matching /ORA-02290/. The assertion fails against the pre-change case (which routes 2290 to StatementInvalid via super), confirming the regression-detection power.
  • No new public surface, no behavior change for non-2290 errors. Surfaced during a Rails-side follow-up audit prompted by Query command for read-only database queries rails/rails#57156 (see the survey in conversation; this is the one clean gap that emerged).

Test plan

  • bundle exec rspec spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb — 205 examples, 0 failures, 1 pending (no regression in the surrounding schema_statements_spec.rb, including the existing check constraints and foreign keys integration tests). Oracle Free 23.26 / FREEPDB1.
  • Re-ran the same single example against the pre-change case for negative control — fails with expected ActiveRecord::CheckViolation, got #<ActiveRecord::StatementInvalid …ORA-02290…>, confirming the assertion exercises the new branch.
  • bundle exec rubocop . — 104 files, no offenses.

Oracle raises ORA-02290 ("check constraint (...) violated") when an
INSERT or UPDATE produces a row that fails a `CHECK` constraint.
oracle-enhanced's `translate_exception` had no entry for code 2290,
so the error fell through to AbstractAdapter#translate_exception and
surfaced as a generic `ActiveRecord::StatementInvalid`. Applications
catching constraint violations could not distinguish a check failure
from any other statement error.

Map 2290 to `ActiveRecord::CheckViolation`, alongside the existing
constraint-violation mappings:

- ORA-01400 -> NotNullViolation
- ORA-02290 -> CheckViolation        (this PR)
- ORA-02291 / 02292 -> InvalidForeignKey
- ORA-12899 -> ValueTooLong

oracle-enhanced has supported `add_check_constraint` /
`t.check_constraint` since rsim#2717; the missing exception mapping was the
remaining gap on the CHECK-constraint surface.

Adds a direct integration assertion in the existing "check constraints"
describe block of `schema_statements_spec.rb`: create a check constraint
on `test_products`, attempt an INSERT that violates it, expect
`ActiveRecord::CheckViolation` with a message matching `/ORA-02290/`.
The assertion fails against the pre-change `case` (which maps 2290 to
`StatementInvalid` via `super`), confirming the spec's regression-
detection power.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yahonda yahonda merged commit f23df2a into rsim:master May 13, 2026
15 of 16 checks passed
@yahonda yahonda deleted the translate-check-violation branch May 13, 2026 01:02
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