Skip to content

fix(#663): adapt psycopg JSON records for Arrow COPY - #665

Merged
cofin merged 2 commits into
mainfrom
fix/load-record-bugs
Aug 1, 2026
Merged

fix(#663): adapt psycopg JSON records for Arrow COPY#665
cofin merged 2 commits into
mainfrom
fix/load-record-bugs

Conversation

@cofin

@cofin cofin commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

  • prepare psycopg record mappings before Arrow schema inference so JSON object shapes are preserved
  • prepare nested Arrow-derived rows before sync and async COPY writes
  • add real PostgreSQL coverage for JSON, JSONB, nullable mappings, and native text arrays

Root cause

load_from_records() normalized mappings into an Arrow table. JSON mappings became Arrow struct values and were passed back to psycopg COPY as Python dictionaries, which psycopg cannot adapt in text COPY mode. Preparing only after Arrow inference would also normalize heterogeneous JSON object shapes, so psycopg now applies its existing parameter configuration before inference and retains schema-gated preparation for direct Arrow inputs.

Closes #663.

@codecov-commenter

codecov-commenter commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.23%. Comparing base (ce2b042) to head (3a1f7eb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #665      +/-   ##
==========================================
+ Coverage   77.22%   77.23%   +0.01%     
==========================================
  Files         475      475              
  Lines       67824    67833       +9     
  Branches     9322     9322              
==========================================
+ Hits        52374    52394      +20     
+ Misses      12042    12033       -9     
+ Partials     3408     3406       -2     
Flag Coverage Δ
py3.10 75.53% <100.00%> (+0.01%) ⬆️
py3.11 75.55% <100.00%> (+0.01%) ⬆️
py3.12 75.54% <100.00%> (+0.01%) ⬆️
py3.13 75.57% <100.00%> (+0.03%) ⬆️
py3.14 76.42% <100.00%> (-0.01%) ⬇️
unit 64.72% <15.38%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sqlspec/adapters/psycopg/_typing.py 93.75% <ø> (ø)
sqlspec/adapters/psycopg/driver.py 84.49% <100.00%> (+0.13%) ⬆️
sqlspec/driver/_async.py 78.18% <100.00%> (+0.04%) ⬆️
sqlspec/driver/_common.py 82.37% <100.00%> (+0.82%) ⬆️
sqlspec/driver/_sync.py 78.98% <100.00%> (+0.04%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cofin
cofin marked this pull request as ready for review August 1, 2026 16:39
@cofin
cofin merged commit a3a3012 into main Aug 1, 2026
23 checks passed
@cofin
cofin deleted the fix/load-record-bugs branch August 1, 2026 22:27
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.

psycopg load_from_records cannot adapt mappings for JSONB columns

2 participants