MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / _make_constructor

Method _make_constructor

asyncpg/exceptions/_base.py:100–154  ·  view source on GitHub ↗
(cls, fields, query=None)

Source from the content-addressed store, hash-verified

98
99 @classmethod
100 def _make_constructor(cls, fields, query=None):
101 dct = cls._get_error_dict(fields, query)
102
103 exccls = cls._get_error_class(fields)
104 message = dct.get('message', '')
105
106 # PostgreSQL will raise an exception when it detects
107 # that the result type of the query has changed from
108 # when the statement was prepared.
109 #
110 # The original error is somewhat cryptic and unspecific,
111 # so we raise a custom subclass that is easier to handle
112 # and identify.
113 #
114 # Note that we specifically do not rely on the error
115 # message, as it is localizable.
116 is_icse = (
117 exccls.__name__ == 'FeatureNotSupportedError' and
118 _is_asyncpg_class(exccls) and
119 dct.get('server_source_function') == 'RevalidateCachedQuery'
120 )
121
122 if is_icse:
123 exceptions = sys.modules[exccls.__module__]
124 exccls = exceptions.InvalidCachedStatementError
125 message = ('cached statement plan is invalid due to a database '
126 'schema or configuration change')
127
128 is_prepared_stmt_error = (
129 exccls.__name__ in ('DuplicatePreparedStatementError',
130 'InvalidSQLStatementNameError') and
131 _is_asyncpg_class(exccls)
132 )
133
134 if is_prepared_stmt_error:
135 hint = dct.get('hint', '')
136 hint += textwrap.dedent("""\
137
138 NOTE: pgbouncer with pool_mode set to "transaction" or
139 "statement" does not support prepared statements properly.
140 You have two options:
141
142 * if you are using pgbouncer for connection pooling to a
143 single server, switch to the connection pool functionality
144 provided by asyncpg, it is a much better option for this
145 purpose;
146
147 * if you have no option of avoiding the use of pgbouncer,
148 then you can set statement_cache_size to 0 when creating
149 the asyncpg connection object.
150 """)
151
152 dct['hint'] = hint
153
154 return exccls, message, dct
155
156 def as_dict(self):
157 dct = {}

Callers 2

newMethod · 0.80
newMethod · 0.80

Calls 4

_is_asyncpg_classFunction · 0.85
_get_error_dictMethod · 0.80
_get_error_classMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected