diff --git a/asyncpg/connection.py b/asyncpg/connection.py index 365ab416..73cb6e66 100644 --- a/asyncpg/connection.py +++ b/asyncpg/connection.py @@ -1416,6 +1416,7 @@ def _mark_stmts_as_closed(self): def _maybe_gc_stmt(self, stmt): if ( stmt.refs == 0 + and stmt.name and not self._stmt_cache.has( (stmt.query, stmt.record_class, stmt.ignore_custom_codec) )