Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions 9 asyncpg/exceptions/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ def __init__(self, msg, *, detail=None, hint=None):
InterfaceMessage.__init__(self, detail=detail, hint=hint)
Exception.__init__(self, msg)

def with_msg(self, msg):
return type(self)(
msg,
detail=self.detail,
hint=self.hint,
).with_traceback(
self.__traceback__
)


class DataError(InterfaceError, ValueError):
"""An error caused by invalid query input."""
Expand Down
13 changes: 12 additions & 1 deletion 13 asyncpg/protocol/codecs/record.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,20 @@ cdef anonymous_record_decode(ConnectionSettings settings, FRBuffer *buf):
return result


cdef anonymous_record_encode(ConnectionSettings settings, WriteBuffer buf, obj):
raise exceptions.UnsupportedClientFeatureError(
'input of anonymous composite types is not supported',
hint=(
'Consider declaring an explicit composite type and '
'using it to cast the argument.'
),
detail='PostgreSQL does not implement anonymous composite type input.'
)


cdef init_record_codecs():
register_core_codec(RECORDOID,
<encode_func>NULL,
<encode_func>anonymous_record_encode,
<decode_func>anonymous_record_decode,
PG_FORMAT_BINARY)

Expand Down
8 changes: 5 additions & 3 deletions 8 asyncpg/protocol/prepared_stmt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ cdef class PreparedStatementState:
except (AssertionError, exceptions.InternalClientError):
# These are internal errors and should raise as-is.
raise
except exceptions.InterfaceError:
# This is already a descriptive error.
raise
except exceptions.InterfaceError as e:
# This is already a descriptive error, but annotate
# with argument name for clarity.
raise e.with_msg(
f'query argument ${idx + 1}: {e.args[0]}') from None
except Exception as e:
# Everything else is assumed to be an encoding error
# due to invalid input.
Expand Down
7 changes: 7 additions & 0 deletions 7 tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,13 @@ async def test_composites(self):

self.assertEqual(res, (None, 1234, '5678', (42, '42')))

with self.assertRaisesRegex(
asyncpg.UnsupportedClientFeatureError,
'query argument \\$1: input of anonymous '
'composite types is not supported',
):
await self.con.fetchval("SELECT (1, 'foo') = $1", (1, 'foo'))

try:
st = await self.con.prepare('''
SELECT ROW(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.