CodeSampleX

Beispiel

sqlalchemy 2.0.51: Connection

Verifiziertes Beispiel für pypi sqlalchemy 2.0.51: Connection. Der Vertrag lief auf python 3.12 · linux debian/x64 · docker und bestand.

sha256:ab99f1edcf8b8c154c8b3328fe3b12391efa216e7f37522cc28e697a1f805b3c

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung python linux 24 · ubuntu · glibc 2.39 x64 python python pip

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104…
2026-09-06

Fall

HOW
Ziel
verify sqlalchemy.Connection in pkg:pypi/sqlalchemy@2.0.51
Pakete
Symbole
  • sqlalchemy.Connection
Umgebung
python
Erstellt
2026-09-06T02:57:46Z

Contract

  1. Connection executes SQL statements returning Result objects, supporting parameter binding and scalar extraction.
  2. Connection context manager automatically closes the connection upon exiting the block.
  3. Statements executed on Connection trigger autobegin, and calling begin() while autobegin is active raises InvalidRequestError.
  4. Connection.begin_nested() creates a savepoint transaction that can be committed or rolled back independently.
  5. Operations on a closed Connection raise ResourceClosedError.

Dateien

  • NOTES.md
  • PROMPT.md
  • csx.json
  • requirements.txt
  • spec.json
  • test/contract.py

Quellartefakt herunterladen (tar.gz)

Quelltext

NOTES.md
# sqlalchemy Connection API

This sample pins `sqlalchemy` 2.0.51 and verifies `sqlalchemy.Connection` for database execution and transaction lifecycle management.

The contract verifies:
- Connection executes SQL statements returning Result objects, supporting parameter binding and scalar extraction.
- Connection context manager automatically closes the connection upon exiting the block.
- Statements executed on Connection trigger autobegin, and calling begin() while autobegin is active raises InvalidRequestError.
- Connection.begin_nested() creates a savepoint transaction that can be committed or rolled back independently.
- Operations on a closed Connection raise ResourceClosedError.
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify sqlalchemy.Connection in pkg:pypi/sqlalchemy@2.0.51
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/sqlalchemy@2.0.51
Demonstrate these symbols/APIs:
  - sqlalchemy.Connection

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:a843d007b6fff36dafaaa76ac7a915fd7ca3ab271e5fc460989ce80c9f312953","contract":["Connection executes SQL statements returning Result objects, supporting parameter binding and scalar extraction.","Connection context manager automatically closes the connection upon exiting the block.","Statements executed on Connection trigger autobegin, and calling begin() while autobegin is active raises InvalidRequestError.","Connection.begin_nested() creates a savepoint transaction that can be committed or rolled back independently.","Operations on a closed Connection raise ResourceClosedError."],"goal":"verify sqlalchemy.Connection in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.Connection"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"subject":"pkg:pypi/sqlalchemy@2.0.51","symbols":["sqlalchemy.Connection"],"verifierAdapter":"python@1"}
requirements.txt
sqlalchemy==2.0.51
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sqlalchemy.Connection in pkg:pypi/sqlalchemy@2.0.51",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/sqlalchemy@2.0.51"
  ],
  "symbols": [
    "sqlalchemy.Connection"
  ]
}
test/contract.py
import sqlalchemy
from sqlalchemy import Connection, create_engine, text
from sqlalchemy.exc import InvalidRequestError, ResourceClosedError

# 1. Verify Connection creation, type, and context manager auto-close
engine = create_engine("sqlite:///:memory:")
with engine.connect() as conn:
    assert isinstance(conn, Connection), f"Expected Connection instance, got {type(conn)}"
    assert conn.engine is engine
    assert not conn.closed
    assert not conn.in_transaction()
assert conn.closed

# 2. Verify SQL execution, parameter binding, scalar extraction, and autobegin behavior
conn = engine.connect()
assert not conn.in_transaction()

# Executing a statement initiates autobegin
result = conn.execute(text("SELECT :x AS val"), {"x": 42})
assert result.scalar_one() == 42
assert conn.in_transaction()

# Calling begin() while autobegin is active raises InvalidRequestError
try:
    conn.begin()
    assert False, "Expected InvalidRequestError when calling begin() on an active transaction"
except InvalidRequestError:
    pass

# Commit ends the active transaction
conn.commit()
assert not conn.in_transaction()

# 3. Verify table operations, multiple parameter execution, and scalar queries
with conn.begin():
    conn.execute(text("CREATE TABLE items (id INT, label TEXT)"))
    conn.execute(
        text("INSERT INTO items (id, label) VALUES (:id, :label)"),
        [{"id": 1, "label": "item1"}, {"id": 2, "label": "item2"}, {"id": 3, "label": "item3"}],
    )

assert not conn.in_transaction()
count = conn.scalar(text("SELECT COUNT(*) FROM items"))
assert count == 3
labels = list(conn.scalars(text("SELECT label FROM items ORDER BY id")))
assert labels == ["item1", "item2", "item3"]
conn.commit()

# 4. Verify nested transaction (savepoint) rollback and commit
with conn.begin():
    sp = conn.begin_nested()
    conn.execute(text("INSERT INTO items (id, label) VALUES (4, 'item4')"))
    assert conn.scalar(text("SELECT COUNT(*) FROM items")) == 4
    sp.rollback()
    assert conn.scalar(text("SELECT COUNT(*) FROM items")) == 3

# 5. Verify operations on a closed Connection raise ResourceClosedError
conn.close()
assert conn.closed
try:
    conn.execute(text("SELECT 1"))
    assert False, "Expected ResourceClosedError when executing on a closed Connection"
except ResourceClosedError:
    pass

print("CONTRACT PASS: sqlalchemy.Connection verified offline")

Ursprungs-Seeder

anonym