Widen Postgrex.Result.t num_rows typespec to include :copy_stream and nil#767
Closed
cgarvis wants to merge 1 commit into
Closed
Widen Postgrex.Result.t num_rows typespec to include :copy_stream and nil#767cgarvis wants to merge 1 commit into
cgarvis wants to merge 1 commit into
Conversation
The COPY IN streaming path sets num_rows to the atom :copy_stream as a sentinel value (protocol.ex:2733), and multi-command transaction results set num_rows to nil (protocol.ex:3099). Both are intentional and tested, but the @type t declaration only allowed integer. Widen num_rows to integer | :copy_stream | nil to match the actual runtime values produced by the driver.
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.
The
@type tdeclaration inPostgrex.Resultdeclaresnum_rows: integer, but the driver produces two other values in practice:num_rows: :copy_stream— set bycopied/1inprotocol.ex(line 2733) as a sentinel while a COPY FROM STDIN stream is in progress.num_rows: nil— set bydone/2inprotocol.ex(line 3099) for multi-command transaction results (e.g.ROLLBACK TO SAVEPOINT ...;RELEASE SAVEPOINT ...).Both values are intentional and have existing test coverage (stream_test.exs lines 412, 681, 709, 749 explicitly assert
num_rows: :copy_stream). The typespec was too narrow.This mismatch is surfaced as a
:badstructfielddiagnostic by the set-theoretic type checker being developed in elixir-lang/elixir#15366.Change
The
@moduledocdescription ofnum_rowsis updated to document the two additional values.Notes for callers
Widening
num_rowsto allow an atom or nil is a typespec-only change with no runtime effect. Downstream code that pattern-matches or arithmetic-operates onnum_rowsassuming it is always an integer was already broken at runtime; this change makes the contract explicit.Compile and test status
mix compileis clean under both the standard Elixir release and the local Elixir build from elixir-lang/elixir#15366.The full test suite requires a running PostgreSQL instance. Tests pass locally where Postgres is available; CI will provide full coverage.