Skip to content

Primary key violation should result in RecordNotUnique error #940

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

Merged

Conversation

aidanharan
Copy link
Contributor

@aidanharan aidanharan commented Aug 30, 2021

Creating a record that violates a primary key constraint should throw an ActiveRecord::RecordNotUnique error rather than the generic ActiveRecord::StatementInvalid error.

The issue was caused by how the adapter was translating MSSQL errors into ActiveRecord errors. We were handling unique key violations but not primary key violations.

Fixes #939

@aidanharan aidanharan marked this pull request as ready for review August 30, 2021 16:45
@wpolicarpo wpolicarpo merged commit b7e52f7 into rails-sqlserver:main Aug 31, 2021
lavika pushed a commit to lavika/activerecord-sqlserver-adapter that referenced this pull request Sep 26, 2023
…qlserver#940)

* Primary key violation should result in ActiveRecord::RecordNotUnique error

* Updated changelog

Co-authored-by: Aidan Haran <aharan@fusioneer.com>
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.

ActiveRecord::StatementInvalid raised in case of duplicate key
2 participants