Skip to content

Correctly treat top level JSONB null value#991

Merged
tsg merged 4 commits into
mainfrom
fix-json-null
Jul 13, 2026
Merged

Correctly treat top level JSONB null value#991
tsg merged 4 commits into
mainfrom
fix-json-null

Conversation

@tsg

@tsg tsg commented Jul 10, 2026

Copy link
Copy Markdown
Member

Description

We have an issue where if a jsonb column is null, not the usual Postgres NULL, but as json null (DEFAULT 'null'::jsonb in postgres speak), the following was happening:

  • Go pgx deserialized it as a regular nil
  • When inserting it was transformed in a postgres NULL
  • if the column has a NOT NULL constraint, the insert fails.

Checked and this was an issue for snapshot only. The wal2json code path doesn't have this issue.

Type of Change

Please select the relevant option(s):

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔨 Build/CI changes
  • 🧹 Code cleanup

Changes Made

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is well-commented
  • Documentation updated where necessary

Additional Notes

@tsg tsg enabled auto-merge (squash) July 10, 2026 10:37
@github-actions

Copy link
Copy Markdown

Merging this branch changes the coverage (3 decrease, 1 increase)

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/internal/postgres 30.52% (-0.85%) 👎
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/data 77.14% (-0.96%) 👎
github.com/xataio/pgstream/pkg/stream 40.19% (+0.30%) 👍
github.com/xataio/pgstream/pkg/stream/integration 0.00% (ø)
github.com/xataio/pgstream/pkg/wal/processor/postgres 78.17% (-0.23%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/internal/postgres/pg_conn_pool.go 0.00% (ø) 48 (+8) 0 48 (+8)
github.com/xataio/pgstream/internal/postgres/pg_utils.go 46.72% (-2.90%) 137 (+8) 64 73 (+8) 👎
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/data/config.go 0.00% (ø) 17 0 17
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/data/pg_snapshot_generator.go 83.25% (-1.21%) 209 (+3) 174 35 (+3) 👎
github.com/xataio/pgstream/pkg/stream/config.go 84.80% (+0.63%) 125 (+5) 106 (+5) 19 👍
github.com/xataio/pgstream/pkg/stream/stream_run.go 0.00% (ø) 89 (+1) 0 89 (+1)
github.com/xataio/pgstream/pkg/stream/stream_snapshot.go 0.00% (ø) 28 (+1) 0 28 (+1)

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/xataio/pgstream/internal/postgres/pg_utils_integration_test.go
  • github.com/xataio/pgstream/pkg/stream/config_test.go
  • github.com/xataio/pgstream/pkg/stream/integration/snapshot_pg_integration_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/jsonb_serialization_test.go

@tsg tsg merged commit 1f24abc into main Jul 13, 2026
8 checks passed
@tsg tsg deleted the fix-json-null branch July 13, 2026 07:35
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.

2 participants