Repository navigation
fix(db): ComplexHelper must not register enum/composite types on the connection (0.15.1) - #55
Merged
Merged
Conversation
…k into the connection)
…ng cursor only, never on the connection (Fixes #54) Bump to 0.15.1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…te loader classes, docs wording, more tests Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…_jsonb for complex columns (deterministic plain values); enum[] inside a composite is detected as an enum Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Fixes #54
Bug
ComplexHelpercalledregister_enum/register_compositeon the connection. psycopg's registration is global to a connection and so sticks to it in a pool: after anypg_*call with a helper (and since 0.15'scomplex_helper="auto", anypg_*call on a table with enum/composite columns), a plainSELECT 'idle'::some_enumon the same connection returned psycopg's auto-numberedEnummember instead of the label, and composites came back as namedtuples.Design
pg_insert,pg_update*,pg_upsert*,*_many, andtestdb.schemaseeding) register the enum/composite adapters on the cursor that runs the statement (psycopg copies the connection's adapters per cursor), and only for columns where a dict/list value had to be converted. New publicComplexHelper.register_on(context, info)for callers ofrecursive_convert.info.enum/info.python_type(needed byrecursive_convert) are materialised in a scratchAdaptersMapthat no connection or cursor sees; a module-levelmake_objectkeeps psycopg's generated-loader-class cache from growing on every registration (a test covers it).pg_retrieve*) already useto_jsonb(...)and need no registration.RETURNINGofpg_insert/pg_update_dict/pg_upsert_dictnow does the same, so results no longer depend on which columns were written.complex_helper="auto",cache=False,clear_cache()unchanged.create type onlyarr as (ms mood[])) failed withExpected EnumInfo, got CompositeInfo; array types now report their element type'styptype.load_all_complex_typesnow orders columns byordinal_position(needed for the raw-tuple RETURNING ofpg_update_dict).Behaviour changes that need a human decision
RETURNINGrows with acomplex_helperare now plain values (composite as dict, enum as label), likepg_retrieve; in 0.15 a converted column came back as the registered object (composite namedtuple /Enummember), others as text, depending on input. Without a helper: unchangedRETURNING *.recursive_convertused directly no longer works with a plaincon.executeof the converted value: register on the cursor first (await helper.register_on(cur, info)); registering on the connection restores the old global behaviour.testdb.schemaseeding no longer leaves types registered on the connection (reads of seeded enum/composite columns on that connection are now label / text).ComplexHelper.registeredis kept as a deprecated shim (always empty, setter ignored,DeprecationWarning), so this stays a patch release (0.15.1).Tests
pg_*helper (retrieve, retrieve_many, insert, update, upsert,*_many, with"auto", a helper,cache=False); the issue's snippet; a one-connectionPgPoolvariant (use, release, plain query on the same backend pid);register_onscoped to the cursor incl. nested types; deterministic RETURNING in both orderings; enum-array-in-composite; loader cache does not grow; deprecated shim. Existing complex-type / crud / testdb tests adapted where they asserted the old leaking or object-valued behaviour.requires_podman-gated as before; also run locally against a private Postgres 18 (24+ live tests green),ty checkandpytest -m "not mssql"green.Version 0.15.1 (+
uv lock).🤖 Generated with Claude Code