edgedb / edgedb-python

The official Python client library for EdgeDB
https://edgedb.com
Apache License 2.0
366 stars 43 forks source link

Retry without capabilities if parse fails #493

Closed fantix closed 2 weeks ago

fantix commented 1 month ago

Describe the bug

If parse() raises a retriable error, we should always retry even if the capabilities is unknown.

Additional context

│ /home/maurice/Dropbox/Projects/banquet/canapes-backend/.venv/lib/python3.10/site-packages/edgedb │
│ /base_client.py:746 in _query                                                                    │
│                                                                                                  │
│   743 │   async def _query(self, query_context: abstract.QueryContext):                          │
│   744 │   │   con = await self._impl.acquire()                                                   │
│   745 │   │   try:                                                                               │
│ ❱ 746 │   │   │   return await con.raw_query(query_context)                                      │
│   747 │   │   finally:                                                                           │
│   748 │   │   │   await self._impl.release(con)                                                  │
│   749                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │           con = <AsyncIOConnection [closed] 0x7981448260a0>                                  │ │
│ │ query_context = QueryContext(                                                                │ │
│ │                 │   query=QueryWithArgs(                                                     │ │
│ │                 │   ),                                                                       │ │
│ │                 │   cache=QueryCache(                                                        │ │
│ │                 │   │   codecs_registry=<edgedb.protocol.protocol.CodecsRegistry object at   │ │
│ │                 0x79815e893800>,                                                             │ │
│ │                 │   │   query_cache=<edgedb.protocol.protocol.QueryCodecsCache object at     │ │
│ │                 0x79815e894790>                                                              │ │
│ │                 │   ),                                                                       │ │
│ │                 │   query_options=QueryOptions(                                              │ │
│ │                 │   │   output_format=<OutputFormat.BINARY: 98>,                             │ │
│ │                 │   │   expect_one=True,                                                     │ │
│ │                 │   │   required_one=False                                                   │ │
│ │                 │   ),                                                                       │ │
│ │                 │   retry_options=<edgedb.options.RetryOptions object at 0x79815e938520>,    │ │
│ │                 │   state=<edgedb.options.State object at 0x79815e88b6c0>                    │ │
│ │                 )                                                                            │ │
│ │          self = <edgedb.asyncio_client.AsyncIOClient object at 0x79815e9b9580>               │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /home/maurice/Dropbox/Projects/banquet/canapes-backend/.venv/lib/python3.10/site-packages/edgedb │
│ /base_client.py:262 in raw_query                                                                 │
│                                                                                                  │
│   259 │   │   │   │   │   capabilities != 0                                                      │
│   260 │   │   │   │   │   and not isinstance(e, errors.TransactionConflictError)                 │
│   261 │   │   │   │   ):                                                                         │
│ ❱ 262 │   │   │   │   │   raise e                                                                │
│   263 │   │   │   │   rule = query_context.retry_options.get_rule_for_exception(e)               │
│   264 │   │   │   │   if i >= rule.attempts:                                                     │
│   265 │   │   │   │   │   raise e                                                                │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │          args = {                                                                            │ │
│ │                 │   'query': '        WITH\n          template_part := (SELECT               │ │
│ │                 TemplatePart\n                   '+418,                                      │ │
│ │                 │   'args': (),                                                              │ │
│ │                 │   'kwargs': {                                                              │ │
│ │                 │   },                                                                       │ │
│ │                 │   'reg': <edgedb.protocol.protocol.CodecsRegistry object at                │ │
│ │                 0x79815e893800>,                                                             │ │
│ │                 │   'qc': <edgedb.protocol.protocol.QueryCodecsCache object at               │ │
│ │                 0x79815e894790>,                                                             │ │
│ │                 │   'output_format': <OutputFormat.BINARY: 98>,                              │ │
│ │                 │   'expect_one': True,                                                      │ │
│ │                 │   'required_one': False,                                                   │ │
│ │                 │   'allow_capabilities': <Capability.EXECUTE: 18446744073709551609>,        │ │
│ │                 │   'state': {}                                                              │ │
│ │                 }                                                                            │ │
│ │    cache_item = None                                                                         │ │
│ │  capabilities = None                                                                         │ │
│ │             i = 1                                                                            │ │
│ │ query_context = QueryContext(                                                                │ │
│ │                 │   query=QueryWithArgs(                                                     │ │
│ │                 │   │   query='        WITH\n          template_part := (SELECT              │ │
│ │                 TemplatePart\n                   '+418,                                      │ │
│ │                 │   │   args=(),                                                             │ │
│ │                 │   │   kwargs={                                                             │ │
│ │                 │   │   }                                                                    │ │
│ │                 │   ),                                                                       │ │
│ │                 │   cache=QueryCache(                                                        │ │
│ │                 │   │   codecs_registry=<edgedb.protocol.protocol.CodecsRegistry object at   │ │
│ │                 0x79815e893800>,                                                             │ │
│ │                 │   │   query_cache=<edgedb.protocol.protocol.QueryCodecsCache object at     │ │
│ │                 0x79815e894790>                                                              │ │
│ │                 │   ),                                                                       │ │
│ │                 │   query_options=QueryOptions(                                              │ │
│ │                 │   │   output_format=<OutputFormat.BINARY: 98>,                             │ │
│ │                 │   │   expect_one=True,                                                     │ │
│ │                 │   │   required_one=False                                                   │ │
│ │                 │   ),                                                                       │ │
│ │                 │   retry_options=<edgedb.options.RetryOptions object at 0x79815e938520>,    │ │
│ │                 │   state=<edgedb.options.State object at 0x79815e88b6c0>                    │ │
│ │                 )                                                                            │ │
│ │     reconnect = False                                                                        │ │
│ │          self = <AsyncIOConnection [closed] 0x7981448260a0>                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /home/maurice/Dropbox/Projects/banquet/canapes-backend/.venv/lib/python3.10/site-packages/edgedb │
│ /base_client.py:238 in raw_query                                                                 │
│                                                                                                  │
│   235 │   │   │   │   │   │   **args                                                             │
│   236 │   │   │   │   │   )                                                                      │
│   237 │   │   │   │   else:                                                                      │
│ ❱ 238 │   │   │   │   │   return await self._protocol.query(**args)                              │
│   239 │   │   │   except errors.EdgeDBError as e:                                                │
│   240 │   │   │   │   if query_context.retry_options is None:                                    │
│   241 │   │   │   │   │   raise                                                                  │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │          args = {                                                                            │ │
│ │                 │   'query': '        WITH\n          template_part := (SELECT               │ │
│ │                 TemplatePart\n                   '+418,                                      │ │
│ │                 │   'args': (),                                                              │ │
│ │                 │   'kwargs': {                                                              │ │
│ │                 │   },                                                                       │ │
│ │                 │   'reg': <edgedb.protocol.protocol.CodecsRegistry object at                │ │
│ │                 0x79815e893800>,                                                             │ │
│ │                 │   'qc': <edgedb.protocol.protocol.QueryCodecsCache object at               │ │
│ │                 0x79815e894790>,                                                             │ │
│ │                 │   'output_format': <OutputFormat.BINARY: 98>,                              │ │
│ │                 │   'expect_one': True,                                                      │ │
│ │                 │   'required_one': False,                                                   │ │
│ │                 │   'allow_capabilities': <Capability.EXECUTE: 18446744073709551609>,        │ │
│ │                 │   'state': {}                                                              │ │
│ │                 }                                                                            │ │
│ │    cache_item = None                                                                         │ │
│ │  capabilities = None                                                                         │ │
│ │             i = 1                                                                            │ │
│ │ query_context = QueryContext(                                                                │ │
│ │                 │   query=QueryWithArgs(                                                     │ │
│ │                 │   │   query='        WITH\n          template_part := (SELECT              │ │
│ │                 TemplatePart\n                   '+418,                                      │ │
│ │                 │   │   args=(),                                                             │ │
│ │                 │   │   kwargs={                                                             │ │
│ │                 │   │   }                                                                    │ │
│ │                 │   ),                                                                       │ │
│ │                 │   cache=QueryCache(                                                        │ │
│ │                 │   │   codecs_registry=<edgedb.protocol.protocol.CodecsRegistry object at   │ │
│ │                 0x79815e893800>,                                                             │ │
│ │                 │   │   query_cache=<edgedb.protocol.protocol.QueryCodecsCache object at     │ │
│ │                 0x79815e894790>                                                              │ │
│ │                 │   ),                                                                       │ │
│ │                 │   query_options=QueryOptions(                                              │ │
│ │                 │   │   output_format=<OutputFormat.BINARY: 98>,                             │ │
│ │                 │   │   expect_one=True,                                                     │ │
│ │                 │   │   required_one=False                                                   │ │
│ │                 │   ),                                                                       │ │
│ │                 │   retry_options=<edgedb.options.RetryOptions object at 0x79815e938520>,    │ │
│ │                 │   state=<edgedb.options.State object at 0x79815e88b6c0>                    │ │
│ │                 )                                                                            │ │
│ │     reconnect = False                                                                        │ │
│ │          self = <AsyncIOConnection [closed] 0x7981448260a0>                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ in query:594                                                                                     │
│                                                                                                  │
│ in execute:528                                                                                   │
│                                                                                                  │
│ in _parse:295                                                                                    │
│                                                                                                  │
│ in wait_for_message:61                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ClientConnectionClosedError