Spaces:
Paused
Paused
Download scratch/verify_db_fix.py from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scratch/verify_db_fix.py
- Command line
-
hf download hf://spaces/3SCError404/nexus/scratch/verify_db_fix.py
-
curl -L -o verify_db_fix.py https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scratch/verify_db_fix.py
1.59 kB
| import asyncio | |
| import os | |
| from sqlalchemy.ext.asyncio import create_async_engine | |
| from sqlalchemy.pool import NullPool | |
| from sqlalchemy import text | |
| # This script verifies that the new lambda signature works with asyncpg | |
| # and that it successfully prevents named prepared statements. | |
| async def verify_fix(): | |
| url = os.environ.get("DATABASE_URL", "postgresql+asyncpg://postgres:postgres@localhost:5432/postgres") | |
| if "postgresql://" in url and "asyncpg" not in url: | |
| url = url.replace("postgresql://", "postgresql+asyncpg://") | |
| print(f"Testing with URL: {url.split('@')[-1]}") | |
| engine = create_async_engine( | |
| url, | |
| poolclass=NullPool, | |
| connect_args={ | |
| "statement_cache_size": 0, | |
| "prepared_statement_name_func": lambda _: None, # The fix | |
| "max_cached_statement_lifetime": 0, | |
| "max_cacheable_statement_size": 0, | |
| } | |
| ) | |
| try: | |
| async with engine.connect() as conn: | |
| # Query 1 | |
| res1 = await conn.execute(text("SELECT 1")) | |
| print(f"Query 1 success: {res1.scalar()}") | |
| # Query 2 (This often fails if naming is broken and pgbouncer is used) | |
| res2 = await conn.execute(text("SELECT 2")) | |
| print(f"Query 2 success: {res2.scalar()}") | |
| print("SUCCESS: Engine connects and executes multiple queries without prep conflicts.") | |
| except Exception as e: | |
| print(f"FAILURE: {e}") | |
| finally: | |
| await engine.dispose() | |
| if __name__ == "__main__": | |
| asyncio.run(verify_fix()) | |