Skip to content

fix: Scan accepts raw 12-byte IDs from binary columns - #117

Merged
rs merged 1 commit into
rs:masterfrom
sonnemusk:fix/scan-raw-bytes
Jul 24, 2026
Merged

rs merged 1 commit into
rs:masterfrom
sonnemusk:fix/scan-raw-bytes

Conversation

@sonnemusk

Copy link
Copy Markdown
Contributor

Summary

(*ID).Scan always called UnmarshalText. Binary SQL columns (BYTEA, etc.) return the raw 12-byte form, which failed as invalid base32.

If len(val) == 12, copy bytes like FromBytes; otherwise keep the text path.

Test plan

  • go test -run TestIDDriverScan

Scan always used UnmarshalText, so BYTEA / binary drivers returning
the 12-byte form failed. Route rawLen slices through FromBytes-style
copy; keep text decoding for the base32 form.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes xid.ID’s sql.Scanner implementation to correctly handle binary SQL column values that arrive as raw 12-byte IDs (e.g., BYTEA/BINARY), while preserving existing behavior for text/base32-encoded values.

Changes:

  • Update (*ID).Scan to accept raw 12-byte []byte values by copying directly into the ID.
  • Keep the existing text/base32 decoding path for non-12-byte []byte and string inputs.
  • Add a unit test covering scanning raw 12-byte values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
id.go Extends (*ID).Scan to accept raw 12-byte binary values in addition to base32 text.
id_test.go Adds a regression test ensuring Scan succeeds for raw 12-byte IDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rs
rs merged commit 40a728c into rs:master Jul 24, 2026
6 of 8 checks passed
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.

3 participants