René's URL Explorer Experiment


Title: Resolve typecasts for composite types, domains and arrays by OID by Cito · Pull Request #145 · PyGreSQL/PyGreSQL · GitHub

Open Graph Title: Resolve typecasts for composite types, domains and arrays by OID by Cito · Pull Request #145 · PyGreSQL/PyGreSQL

X Title: Resolve typecasts for composite types, domains and arrays by OID by Cito · Pull Request #145 · PyGreSQL/PyGreSQL

Description: Typecasts for composite types, domains and arrays are now created from their fields, base type and element type as looked up by OID, no longer by type name. This fixes a regression from e02ec7c and the older problem behind it. Background Typecasts are set for type names, e.g. set_typecast('t', func). When no typecast was set for a type, PyGreSQL derived one from the name: for an array _t, it stripped the underscore and used the typecast for t; for a composite type or domain t, it looked up the fields or the base type by the name t. Type names are ambiguous, though: the type may not be in the search path, other schemas may have a type with the same name, and array type names are not always the element type name with an underscore (_q_1 if _q is taken). Before e02ec7c, the name was looked up with '"t"'::regtype. For a type outside the search path, this raised an error on the server. PyGreSQL caught it and treated the type as unknown, but the transaction was already aborted. In pgdb this happened in normal queries: after select array[(1,'x')::s.t] with a composite type s.t outside the search path, the fetch and all further queries in the transaction failed with "current transaction is aborted". The same happened for arrays of domains outside the search path. In pg, query() was only affected in corner cases such as arrays named _q_1, but DbTypes.get() with an unknown name also left the transaction aborted. e02ec7c replaced the regtype cast with a query on pg_type, which cannot fail. For unqualified names it selects the type with pg_type_is_visible(), which is true for at most one type per name, so the query returns at most one row, the same type that regtype found. This removed the errors, but not their cause, the lookup by name. Types outside the search path were now simply not found. In pg, the quoting of internal names in e02ec7c also bypassed a cache entry that by chance had made such composite types work, so their values came back as strings. Design A typecast set for the name of a type, by the user or as a default like int4, is used first, as before. It applies to all types with that name. Otherwise, the typecast is derived from the type object: domains use the typecast of the base type (typbasetype), composite types a record cast with the typecasts of their fields (atttypid), arrays an array cast with the typecast and delimiter of the element type (typelem). All of these are looked up by OID. Array types are recognized by is_array_type(): an element type, variable length and a name starting with an underscore. This excludes types such as int2vector, oidvector, name and point, which have an element type but are not cast like arrays. The category is not checked, since it is a pseudo type category for _record. The derived typecasts are cached per connection by OID. The cache is dropped when typecasts are set or reset, also globally, and in pg also by DB.get_attnames(flush=True) and DB.reopen(). Types found by OID are no longer cached under their bare name. Names passed by the user, e.g. get_typecast('s.t'), are parsed like the keys of DbTypes and TypeCache. pg (DbTypes) and pgdb (TypeCache) have separate implementations of this; they share only the small helper is_array_type(). The name-based logic in Typecasts remains for names that are not found in the database and for subclasses that use the get_attnames()/get_fields() hooks. The get_base() hooks, which were new in 6.3, have been removed. Other changes Composite types whose names or field names cannot be used in named tuples (e.g. a field class) are returned as named tuples with the name Record or with renamed fields, instead of raising a ValueError. Arrays of types with another delimiter, like box[], are split correctly. In pg, DB.get_attnames(flush=True) also drops the typecasts for composite types, and DB.reopen() binds the typecasts to the new connection, also when the DB object wraps an existing connection. In pgdb, TypeCache.reset_typecast() no longer stores array casts derived from names, and no longer breaks typecasts that need the connection when called without arguments. Global typecasts set for array types are used, like in pg. Names passed to get_typecast() and typecast() are parsed like the keys of DbTypes and TypeCache in both modules. Type codes in pgdb have a new attribute elem. get_typecast() also accepts type objects and OIDs. Docs and changelog have been updated. New tests The new tests in tests/test_classic_dbwrapper.py and tests/test_dbapi20.py cover, in both modules: values of composite types, nested composite types, table columns, row types, arrays and domains in a schema outside the search path; types with the same name in two schemas; typecasts set by name for such types; arrays named _q_1 and composite types named _q; oidvector, name and point; arrays of anonymous records; global typecasts, also for array types, set after values have been cast; names that cannot be used in named tuples; type objects without OID; box[] arrays; altered composite types; qualified names in get_typecast(). The pg tests also check that enum values cause no queries per value and that typecasts work after DB.reopen(), the pgdb tests that resetting typecasts does not break them. Most of them fail on main; the others guard against regressions of the new code.

Open Graph Description: Typecasts for composite types, domains and arrays are now created from their fields, base type and element type as looked up by OID, no longer by type name. This fixes a regression from e02ec7c and...

X Description: Typecasts for composite types, domains and arrays are now created from their fields, base type and element type as looked up by OID, no longer by type name. This fixes a regression from e02ec7c and...

Opengraph URL: https://github.com/PyGreSQL/PyGreSQL/pull/145

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:ee7176f7-8c94-e391-909d-d54f471f1763
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9F90:3C07AF:B4DAA:FBBDB:6B046331
html-safe-nonce321ae80ad8bda23d4643ab22eb3af4723896308348b123fd7c67163823e32e5a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjkwOjNDMDdBRjpCNERBQTpGQkJEQjo2QjA0NjMzMSIsInZpc2l0b3JfaWQiOiIyNDU4NDM2MDA0OTY1ODAyODAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac97fa33d0815f76fb6e8f8640acb0809901bbcbec6d0c7354883223125c1734ec
hovercard-subject-tagpull_request:5449576052
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/PyGreSQL/PyGreSQL/pull/145/files
twitter:imagehttps://avatars.githubusercontent.com/u/464599?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/464599?s=400&v=4
og:image:altTypecasts for composite types, domains and arrays are now created from their fields, base type and element type as looked up by OID, no longer by type name. This fixes a regression from e02ec7c and...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/PyGreSQL/PyGreSQL git https://github.com/PyGreSQL/PyGreSQL.git
octolytics-dimension-user_id60857770
octolytics-dimension-user_loginPyGreSQL
octolytics-dimension-repository_id51212044
octolytics-dimension-repository_nwoPyGreSQL/PyGreSQL
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id51212044
octolytics-dimension-repository_network_root_nwoPyGreSQL/PyGreSQL
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release03e114520787ad27289207f153520ef97461127c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/PyGreSQL/PyGreSQL/pull/145/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPyGreSQL%2FPyGreSQL%2Fpull%2F145%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPyGreSQL%2FPyGreSQL%2Fpull%2F145%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=PyGreSQL%2FPyGreSQL
Reloadhttps://github.com/PyGreSQL/PyGreSQL/pull/145/files
Reloadhttps://github.com/PyGreSQL/PyGreSQL/pull/145/files
Reloadhttps://github.com/PyGreSQL/PyGreSQL/pull/145/files
PyGreSQLhttps://github.com/PyGreSQL
PyGreSQLhttps://github.com/PyGreSQL/PyGreSQL
Codehttps://github.com/PyGreSQL/PyGreSQL
Issues22 (22)https://github.com/PyGreSQL/PyGreSQL/issues
Pull requests1 (1)https://github.com/PyGreSQL/PyGreSQL/pulls
Actionshttps://github.com/PyGreSQL/PyGreSQL/actions
Projectshttps://github.com/PyGreSQL/PyGreSQL/projects
Security and qualityhttps://github.com/PyGreSQL/PyGreSQL/security
Insightshttps://github.com/PyGreSQL/PyGreSQL/insights
Sign up for GitHub https://github.com/signup?return_to=%2FPyGreSQL%2FPyGreSQL%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FPyGreSQL%2FPyGreSQL%2Fissues%2Fnew%2Fchoose
Citohttps://github.com/Cito
mainhttps://github.com/PyGreSQL/PyGreSQL/tree/main
fix-type-lookup-by-oidhttps://github.com/PyGreSQL/PyGreSQL/tree/fix-type-lookup-by-oid
Conversation 2 https://github.com/PyGreSQL/PyGreSQL/pull/145
Commits 2 https://github.com/PyGreSQL/PyGreSQL/pull/145/commits
Checks 22 https://github.com/PyGreSQL/PyGreSQL/pull/145/checks
Files changed https://github.com/PyGreSQL/PyGreSQL/pull/145/files
Please reload this pagehttps://github.com/PyGreSQL/PyGreSQL/pull/145/files
Resolve typecasts for composite types, domains and arrays by OID https://github.com/PyGreSQL/PyGreSQL/pull/145/files#top
Show all changes 2 commits https://github.com/PyGreSQL/PyGreSQL/pull/145/files
6562640 Resolve typecasts for composite types, domains and arrays by OID Cito Nov 23, 2026 https://github.com/PyGreSQL/PyGreSQL/pull/145/commits/6562640d86daa543486f5961b324f5815e2b2310
5a69e1c Set and reset typecasts only for the given type names Cito Nov 23, 2026 https://github.com/PyGreSQL/PyGreSQL/pull/145/commits/5a69e1c3d4cadaeab436823d7c2f1c8f7a3622e0
Clear filters https://github.com/PyGreSQL/PyGreSQL/pull/145/files
Please reload this pagehttps://github.com/PyGreSQL/PyGreSQL/pull/145/files
Please reload this pagehttps://github.com/PyGreSQL/PyGreSQL/pull/145/files
changelog.rst https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-af89d17b84a7470a2e9662d1d1281c96a163ba0c438e476656c4a336a19a120a
db_types.rst https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-142c8418b0b0e5319812549bce21da2de4553b054f4d4be20c7d6198233bf97f
typecache.rst https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
adapt.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
cast.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-880f95701797c038b7462f9922079c6df0c93ef1e3d1a82b99bb0a2fd536d3a0
db.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-69568049815164a8736eeb69d9e57b62da5a3edc75bfcfd2285a7145611f713d
helpers.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-c3926602229c30b028336822da0f1609e10572e02ccf65dbade5f6c4535dbeff
cast.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-a6fb69a851ff2afd71e0044329504da92f8607652af9a2276f011f661ebb672f
typecode.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-c6ef8c99e824fb121116767f6b82da0f0243df1af2cbe81f0489a4ddc9eafafd
test_classic_dbwrapper.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-17a518e29c7197473b0a85feada64b6eef8893c64ab02f0059fee68b112bd340
test_classic_functions.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-4fef0f0f3be4836158fc75667beedc2a6487e8a8c79c976796992ac725770400
test_dbapi20.py https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-785635aa058145400ce9f284bbb47d6a8bcbeabc2f2f707aafe5fa87422263ca
docs/contents/changelog.rsthttps://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-af89d17b84a7470a2e9662d1d1281c96a163ba0c438e476656c4a336a19a120a
View file https://github.com/PyGreSQL/PyGreSQL/blob/5a69e1c3d4cadaeab436823d7c2f1c8f7a3622e0/docs/contents/changelog.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/PyGreSQL/PyGreSQL/pull/145/{{ revealButtonHref }}
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-af89d17b84a7470a2e9662d1d1281c96a163ba0c438e476656c4a336a19a120a
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-af89d17b84a7470a2e9662d1d1281c96a163ba0c438e476656c4a336a19a120a
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-af89d17b84a7470a2e9662d1d1281c96a163ba0c438e476656c4a336a19a120a
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-af89d17b84a7470a2e9662d1d1281c96a163ba0c438e476656c4a336a19a120a
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-af89d17b84a7470a2e9662d1d1281c96a163ba0c438e476656c4a336a19a120a
docs/contents/pg/db_types.rsthttps://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-142c8418b0b0e5319812549bce21da2de4553b054f4d4be20c7d6198233bf97f
View file https://github.com/PyGreSQL/PyGreSQL/blob/5a69e1c3d4cadaeab436823d7c2f1c8f7a3622e0/docs/contents/pg/db_types.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/PyGreSQL/PyGreSQL/pull/145/{{ revealButtonHref }}
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-142c8418b0b0e5319812549bce21da2de4553b054f4d4be20c7d6198233bf97f
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-142c8418b0b0e5319812549bce21da2de4553b054f4d4be20c7d6198233bf97f
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-142c8418b0b0e5319812549bce21da2de4553b054f4d4be20c7d6198233bf97f
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-142c8418b0b0e5319812549bce21da2de4553b054f4d4be20c7d6198233bf97f
docs/contents/pgdb/typecache.rsthttps://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
View file https://github.com/PyGreSQL/PyGreSQL/blob/5a69e1c3d4cadaeab436823d7c2f1c8f7a3622e0/docs/contents/pgdb/typecache.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/PyGreSQL/PyGreSQL/pull/145/{{ revealButtonHref }}
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-8b13abf1302058071290fa7d5a404f31855ad6a0b870706b6cc56be6aaecfe2e
pg/adapt.pyhttps://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
View file https://github.com/PyGreSQL/PyGreSQL/blob/5a69e1c3d4cadaeab436823d7c2f1c8f7a3622e0/pg/adapt.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/PyGreSQL/PyGreSQL/pull/145/{{ revealButtonHref }}
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
https://github.com/PyGreSQL/PyGreSQL/pull/145/files#diff-41a49ecfd8b1e7cd725df849c53aa43e4fd2d977d89a82f41e633a60f34c49e4
Please reload this pagehttps://github.com/PyGreSQL/PyGreSQL/pull/145/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.