Translate ORA-02290 to ActiveRecord::CheckViolation#2790
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CHECKconstraint. oracle-enhanced'stranslate_exception(oracle_enhanced_adapter.rb:1433-1452) had no entry for code 2290, so the error fell through toAbstractAdapter#translate_exceptionand surfaced as a genericActiveRecord::StatementInvalid. Applications catching constraint violations could not distinguish a check failure from any other statement error.ActiveRecord::CheckViolationalongside the existing constraint-violation mappings:NotNullViolationCheckViolation(this PR)InvalidForeignKeyValueTooLongadd_check_constraint/t.check_constraintsince 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 PRActiveRecord::Base.connection.execute(and AR'screate/updatepaths) emit the AR-portableCheckViolationfor check-constraint violations on Oracle, matching the PostgreSQL / MySQL / SQLite3 contract.describe "check constraints"block ofspec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb: create a check constraint ontest_products, attempt an INSERT that violates it, expectActiveRecord::CheckViolationwith a message matching/ORA-02290/. The assertion fails against the pre-changecase(which routes 2290 toStatementInvalidviasuper), confirming the regression-detection power.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 surroundingschema_statements_spec.rb, including the existingcheck constraintsandforeign keysintegration tests). Oracle Free 23.26 / FREEPDB1.casefor negative control — fails withexpected ActiveRecord::CheckViolation, got #<ActiveRecord::StatementInvalid …ORA-02290…>, confirming the assertion exercises the new branch.bundle exec rubocop .— 104 files, no offenses.