Repository navigation
fix(domain): read a log traceback that psycopg returns as a dict - #1038
Merged
janbjorge merged 1 commit intoOct 24, 2026
Merged
Conversation
asyncpg returns the jsonb traceback column as JSON text, psycopg 3 as an already-parsed dict, and the Log.traceback validator passed it to from_json unconditionally. Every log read through PsycopgDriver (queue_log, exception_logs, job_log_history) raised TypeError once a returned row had a traceback. Accept a dict as Job.headers already does.
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.
Agentic
Summary
With
PsycopgDriver, every read of a log row that carries a traceback raisesTypeError: Expected bytes, bytearray or str. asyncpg returns thejsonbtraceback column as JSON text. psycopg 3 returns it already parsed as a dict, and theBeforeValidatoronLog.tracebackcallsfrom_jsonon it unconditionally.I ran a real
QueueManageron each driver against PostgreSQL 16.2, on main (9b8ab84) and on PyPI 1.6.0, nothing mocked. One job raises, one asks for a retry and then succeeds, one raises underon_failure="hold", so three log rows carry a traceback. Then:The two dashboard rows are from main only:
create_web_routermounted on a FastAPI app withapp.state.pgq_queries = Queries(PsycopgDriver(conn)), the way the web dashboard docs describe mounting it in your own app, requested in-process through httpx's ASGI transport.create_web_appand the MCP server build their own asyncpg pool, so they are not affected.queue_log()fails as soon as the log holds one row with a traceback (a job that failed, was held or was retried); the other two fail when a row they return has one.Job.headersis alsojsonband already takes both forms, withx if x is None or isinstance(x, dict) else from_json(x)from #793.Change
The same check on
Log.tracebackinpgqueuer/domain/models.py, +2/-1 in one file (the line plus a comment saying why). Text and bytes still go throughfrom_json,NonestaysNone, and a dict goes straight toTracebackRecordvalidation. With the fix, every psycopg line above readsokor200.Testing
uv sync --frozen && uv run ruff check . && uv run ruff format . --check && uv run lint-imports && uv run mypy . && uv run pytestpassed (PostgreSQL 16.2 throughEXTERNAL_POSTGRES_DSN, Python 3.12; mypy run asmypy . --no-incremental): 1528 passed, 10 skipped. On main: 1524 passed, 10 skipped (the 4 new cases are the difference).test_drivers.pygetstest_log_rows_with_a_traceback_read_back, parametrized over the three async drivers. It logs a job asexceptionwith a traceback throughlog_jobsand reads it back throughqueue_log(),exception_logs()andjob_log_history(). The psycopg case fails on main and passes with the fix; the asyncpg and pool cases pass on both.test_models.pygets a check next to the headers one thatLogtakes the traceback as a dict and as JSON text (fails on main).Checklist