Fix unique_constraint support (en-US errors) - #188
Merged
Merged
Conversation
The en-US row for MSSQL error 2627 in errors.csv used the literal server placeholder '%.*ls' instead of a regex capture group, so Tds.Error.get_constraint_violations/2 returned [] for every en-US message and Ecto.Changeset.unique_constraint never fired (issue #173). The row now uses the same '(\\S+?)' capture as all other locales. query!/prepare!/execute!/close! no longer re-raise a new Tds.Error built from msg_text only; the original error is re-raised so the :mssql metadata (number, msg_text) survives to callers such as Ecto's constraint mapping. Adds unit tests for constraint extraction (2627/2601 en-US, unknown code) and integration tests asserting query!/prepare!/execute! re-raise Tds.Error with mssql metadata intact.
handle_close now runs with state :executing, matching the internal
auto-close path in handle_execute. Previously a server error response
to sp_unprepare (e.g. closing an already-closed handle) was decoded
with state :ready, for which Tds.Messages.parse/3 has no clause, so
the connection process crashed instead of returning {:error,
%Tds.Error{}}.
mjaric
force-pushed
the
fix/issue-173-unique-constraint
branch
from
August 19, 2026 08:18
045f1b0 to
e9ce174
Compare
apt has no download timeout by default, so runner network flakes hang 'apt-get update' indefinitely (observed on run 32232000436: the lint job's apt step sat idle for ~18 minutes until cancellation while the other three jobs finished the same step in under a minute). Add a 30s acquire timeout with up to 3 attempts and cap the step at 10 minutes.
There is no mssql/server:2024-latest tag; Microsoft skipped from 2022 to 2025 (available tags: 2017-latest, 2019-latest, 2022-latest, 2025-latest). Use 2025-latest as the newest major version.
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.
Fixes #173.
What changed
lib/tds/errors.csv: the en-US row for error 2627 used the literal server placeholder%.*lsinstead of a regex capture group, soTds.Error.get_constraint_violations/2returned[]for every en-US message and Ecto'sunique_constraintnever fired. The row now uses the same(\S+?)capture as all other locales.lib/tds.ex:query!/prepare!/execute!/close!no longer re-raise a newTds.Errorbuilt frommsg_textonly; the original error is re-raised so themssqlmetadata (number,msg_text) survives to callers such as Ecto's constraint mapping.lib/tds/protocol.ex:handle_closenow runs with state:executing, matching the internal auto-close path inhandle_execute. A server error response tosp_unprepare(e.g. closing an already-closed handle) previously hit a missingTds.Messages.parse(:ready, ...)clause and crashed the connection process instead of returning{:error, %Tds.Error{}}.Tds.Errorwithmssqlmetadata intact.Verification
Full test suite against a live SQL Server instance: 112 tests, 0 failures.