CodeSampleX

Ejemplo

sqlalchemy 2.0.51: exc.SQLAlchemyError

Muestra verificada para pypi sqlalchemy 2.0.51: exc.SQLAlchemyError. El contrato se ejecutó en python 3.12 · linux debian/x64 · docker y pasó.

sha256:8ced0e97cf9d83c91f764ee579cb8e8692b73625209c9da8f0081d6439825f92

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado python linux 24 · ubuntu · glibc 2.39 x64 python python pip

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify sqlalchemy.exc.SQLAlchemyError in pkg:pypi/sqlalchemy@2.0.51
Paquetes
Símbolos
  • sqlalchemy.exc.SQLAlchemyError
Entorno
python
Creado
2026-09-06T00:59:09Z

Contrato

  1. SQLAlchemyError is the base exception class for all SQLAlchemy errors and inherits from built-in Exception.
  2. Direct instantiation of SQLAlchemyError preserves the exception message.
  3. Core and DBAPI exceptions including ArgumentError, NoSuchTableError, and OperationalError inherit from SQLAlchemyError.
  4. ORM exceptions including NoResultFound and MultipleResultsFound inherit from SQLAlchemyError.
  5. Catching SQLAlchemyError intercepts Core-level statement failures and wraps DBAPI errors with orig attribute preserved.
  6. Catching SQLAlchemyError intercepts ORM scalar query exceptions and engine configuration failures.

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

NOTES.md
# sqlalchemy.exc.SQLAlchemyError API

This sample pins `sqlalchemy` 2.0.51 and verifies `sqlalchemy.exc.SQLAlchemyError` as the base exception class across Core and ORM layers.

The contract verifies:
- `SQLAlchemyError` inherits from built-in `Exception`.
- Instantiating `SQLAlchemyError` directly preserves the error message.
- Core and DBAPI exception classes (such as `ArgumentError`, `NoSuchTableError`, `DBAPIError`, `OperationalError`, `IntegrityError`, `CompileError`, `StatementError`) inherit from `SQLAlchemyError`.
- ORM exception classes (such as `NoResultFound`, `MultipleResultsFound`) inherit from `SQLAlchemyError`.
- Catching `SQLAlchemyError` intercepts Core statement execution failures, preserving underlying DBAPI driver details on `.orig`.
- Catching `SQLAlchemyError` intercepts ORM query execution exceptions (such as `NoResultFound` from `scalar_one()`).
- Catching `SQLAlchemyError` intercepts engine configuration errors (`ArgumentError`).
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.exc.SQLAlchemyError 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.exc.SQLAlchemyError

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:f87355f4375703b4cc223312267eefaf2c0540e6229c9673140e7bd663be6cba","contract":["SQLAlchemyError is the base exception class for all SQLAlchemy errors and inherits from built-in Exception.","Direct instantiation of SQLAlchemyError preserves the exception message.","Core and DBAPI exceptions including ArgumentError, NoSuchTableError, and OperationalError inherit from SQLAlchemyError.","ORM exceptions including NoResultFound and MultipleResultsFound inherit from SQLAlchemyError.","Catching SQLAlchemyError intercepts Core-level statement failures and wraps DBAPI errors with orig attribute preserved.","Catching SQLAlchemyError intercepts ORM scalar query exceptions and engine configuration failures."],"goal":"verify sqlalchemy.exc.SQLAlchemyError in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.exc.SQLAlchemyError"]},"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.exc.SQLAlchemyError"],"verifierAdapter":"python@1"}
requirements.txt
sqlalchemy==2.0.51
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sqlalchemy.exc.SQLAlchemyError in pkg:pypi/sqlalchemy@2.0.51",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/sqlalchemy@2.0.51"
  ],
  "symbols": [
    "sqlalchemy.exc.SQLAlchemyError"
  ]
}
test/contract.py
import sqlalchemy as sa
from sqlalchemy import (
    MetaData,
    Table,
    Column,
    Integer,
    String,
    create_engine,
    select,
)
from sqlalchemy import exc
from sqlalchemy.orm import (
    DeclarativeBase,
    Mapped,
    mapped_column,
    Session,
)

# 1. Base exception inheritance: SQLAlchemyError inherits from Exception
assert issubclass(exc.SQLAlchemyError, Exception), "SQLAlchemyError must inherit from Exception"

# 2. Direct instantiation preserves message
err = exc.SQLAlchemyError("custom error message")
assert str(err) == "custom error message", "Direct instantiation must preserve message"

# 3. Core and DBAPI exception hierarchy
assert issubclass(exc.ArgumentError, exc.SQLAlchemyError), "ArgumentError must subclass SQLAlchemyError"
assert issubclass(exc.NoSuchTableError, exc.SQLAlchemyError), "NoSuchTableError must subclass SQLAlchemyError"
assert issubclass(exc.DBAPIError, exc.SQLAlchemyError), "DBAPIError must subclass SQLAlchemyError"
assert issubclass(exc.OperationalError, exc.SQLAlchemyError), "OperationalError must subclass SQLAlchemyError"
assert issubclass(exc.IntegrityError, exc.SQLAlchemyError), "IntegrityError must subclass SQLAlchemyError"
assert issubclass(exc.CompileError, exc.SQLAlchemyError), "CompileError must subclass SQLAlchemyError"
assert issubclass(exc.NoReferencedTableError, exc.SQLAlchemyError), "NoReferencedTableError must subclass SQLAlchemyError"
assert issubclass(exc.StatementError, exc.SQLAlchemyError), "StatementError must subclass SQLAlchemyError"

# 4. ORM exception hierarchy
assert issubclass(exc.NoResultFound, exc.SQLAlchemyError), "NoResultFound must subclass SQLAlchemyError"
assert issubclass(exc.MultipleResultsFound, exc.SQLAlchemyError), "MultipleResultsFound must subclass SQLAlchemyError"

# 5. Catching Core statement failure intercepts DBAPIError and preserves .orig
engine = create_engine("sqlite:///:memory:")
caught_core = False
try:
    with engine.connect() as conn:
        conn.execute(sa.text("SELECT * FROM non_existent_table"))
except exc.SQLAlchemyError as e:
    caught_core = True
    assert isinstance(e, exc.DBAPIError), f"Expected DBAPIError, got {type(e)}"
    assert hasattr(e, "orig")
    assert e.orig is not None
assert caught_core, "Failed to intercept Core statement error with SQLAlchemyError"

# 6. Catching ORM scalar query error intercepts NoResultFound
class Base(DeclarativeBase):
    pass

class Item(Base):
    __tablename__ = "items"
    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(50))

Base.metadata.create_all(engine)

caught_orm = False
try:
    with Session(engine) as session:
        session.execute(select(Item).where(Item.id == 999)).scalar_one()
except exc.SQLAlchemyError as e:
    caught_orm = True
    assert isinstance(e, exc.NoResultFound), f"Expected NoResultFound, got {type(e)}"
assert caught_orm, "Failed to intercept ORM NoResultFound with SQLAlchemyError"

# 7. Catching configuration error intercepts ArgumentError
caught_arg = False
try:
    create_engine("invalid_scheme://")
except exc.SQLAlchemyError as e:
    caught_arg = True
    assert isinstance(e, exc.ArgumentError), f"Expected ArgumentError, got {type(e)}"
assert caught_arg, "Failed to intercept ArgumentError with SQLAlchemyError"

print("CONTRACT PASS: sqlalchemy.exc.SQLAlchemyError verified offline")

Seeder de origen

anónimo