{"record":{"id":"ef9a6ea76dd9a7eb","repo":"crewAIInc/crewAI","slug":"query-failed-after-all-retries","errorCode":null,"errorMessage":"Query failed after all retries","messagePattern":"Query failed after all retries","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py","lineNumber":246,"sourceCode":"                        with _cache_lock:\n                            _query_cache[self._get_cache_key(query, timeout)] = results\n\n                    return results\n                finally:\n                    cursor.close()\n                    if (\n                        self._pool_lock is not None\n                        and self._connection_pool is not None\n                    ):\n                        with self._pool_lock:\n                            self._connection_pool.append(conn)\n            except (DatabaseError, OperationalError) as e:  # noqa: PERF203\n                if attempt == self.max_retries - 1:\n                    raise\n                await asyncio.sleep(self.retry_delay * (2**attempt))\n                logger.warning(f\"Query failed, attempt {attempt + 1}: {e!s}\")\n                continue\n        raise RuntimeError(\"Query failed after all retries\")\n\n    async def _run(\n        self,\n        query: str,\n        database: str | None = None,\n        snowflake_schema: str | None = None,\n        timeout: int = 300,\n        **kwargs: Any,\n    ) -> Any:\n        \"\"\"Execute the search query.\"\"\"\n        try:\n            if database:\n                await self._execute_query(f\"USE DATABASE {database}\")\n            if snowflake_schema:\n                await self._execute_query(f\"USE SCHEMA {snowflake_schema}\")\n\n            return await self._execute_query(query, timeout)\n        except Exception as e:","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py#L228-L264","documentation":"SnowflakeSearchTool wraps query execution in a retry loop over DatabaseError/OperationalError. On the final attempt it re-raises the original exception, so the trailing `raise RuntimeError(\"Query failed after all retries\")` is effectively unreachable defensive code — in practice you will see the last DatabaseError/OperationalError, not this RuntimeError, unless the loop is exited abnormally.","triggerScenarios":"A Snowflake query raising DatabaseError or OperationalError (connection loss, lock timeout, syntax/permission error) for every attempt up to max_retries; the final attempt re-raises the driver error. The RuntimeError would only surface if the loop ended without re-raising, which the current code structure prevents.","commonSituations":"Persistent failures: wrong warehouse/database, expired or invalid credentials, network partitions to Snowflake, SQL errors that retries cannot fix. Users searching for this exact message usually find the underlying snowflake-connector error instead.","solutions":["Look at the chained/original snowflake-connector exception and the logged 'Query failed, attempt N' warnings — the root cause is there, not in this RuntimeError.","For transient errors, increase max_retries / retry_delay on the tool; for persistent errors (bad SQL, permissions) fix the query or grants — retrying will not help.","Verify connectivity and warehouse status (e.g. warehouse suspended) if errors are OperationalError."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from snowflake.connector.errors import DatabaseError, OperationalError\ntry:\n    result = await tool._run(query=sql)\nexcept (DatabaseError, OperationalError) as e:\n    # final attempt already re-raised the driver error; inspect it for root cause\n    logger.error(\"Snowflake query failed permanently: %s\", e)\n    raise","preventionTips":["Distinguish retryable (connection/timeout) from permanent (SQL/permission) driver errors before retrying.","Set max_retries/retry_delay sized to your Snowflake workload instead of retrying at the caller for persistent errors."],"tags":["snowflake","retry","database-error","query"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}