CodeSampleX

Sample

sqlalchemy 2.0.51: exc.InvalidRequestError

Verified sample for pypi sqlalchemy 2.0.51: exc.InvalidRequestError. The contract ran on python 3.12 · linux debian/x64 · docker and passed.

sha256:390ec80d1882d95d4bf8d7ff16d396deb59e90c5098898bfbbd2056e5f615a06

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment python linux 24 · ubuntu · glibc 2.39 x64 python python pip

Verification-run environments

Environment Contract Stages Run
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-05

Case

HOW
Goal
verify sqlalchemy.exc.InvalidRequestError in pkg:pypi/sqlalchemy@2.0.51
Packages
Symbols
  • sqlalchemy.exc.InvalidRequestError
Environment
python
Created
2026-09-05T23:24:47Z

Contract

  1. InvalidRequestError is a subclass of SQLAlchemyError and represents invalid state or usage errors across SQLAlchemy.
  2. Calling Session.begin() when a transaction is already active raises InvalidRequestError.
  3. Adding an instance already attached to another Session raises InvalidRequestError.
  4. Deleting or refreshing a transient instance that is not persistent in the Session raises InvalidRequestError.
  5. Defining duplicate Table names within the same MetaData collection without extend_existing=True raises InvalidRequestError.
  6. Executing a select query joining tables without a ForeignKey relationship or explicit ON clause raises InvalidRequestError.

Files

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

Download the source artifact (tar.gz)

Source

NOTES.md
# sqlalchemy InvalidRequestError API

This sample pins `sqlalchemy` 2.0.51 and verifies `sqlalchemy.exc.InvalidRequestError` for state and query validation in Core and ORM.

The contract verifies:
- `InvalidRequestError` is a subclass of `SQLAlchemyError` and represents invalid state or usage errors across SQLAlchemy.
- Calling `Session.begin()` when a transaction is already active raises `InvalidRequestError`.
- Adding an instance already attached to another `Session` raises `InvalidRequestError`.
- Deleting or refreshing a transient instance that is not persistent in the `Session` raises `InvalidRequestError`.
- Defining duplicate `Table` names within the same `MetaData` collection without `extend_existing=True` raises `InvalidRequestError`.
- Executing a `select` query joining tables without a `ForeignKey` relationship or explicit `ON` clause raises `InvalidRequestError`.
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.InvalidRequestError 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.InvalidRequestError

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:52e9daa50c3c83b2f6ca3f0a161c5f2f554f1c23f65dd083a68b293ac7a79a49","contract":["InvalidRequestError is a subclass of SQLAlchemyError and represents invalid state or usage errors across SQLAlchemy.","Calling Session.begin() when a transaction is already active raises InvalidRequestError.","Adding an instance already attached to another Session raises InvalidRequestError.","Deleting or refreshing a transient instance that is not persistent in the Session raises InvalidRequestError.","Defining duplicate Table names within the same MetaData collection without extend_existing=True raises InvalidRequestError.","Executing a select query joining tables without a ForeignKey relationship or explicit ON clause raises InvalidRequestError."],"goal":"verify sqlalchemy.exc.InvalidRequestError in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.exc.InvalidRequestError"]},"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.InvalidRequestError"],"verifierAdapter":"python@1"}
requirements.txt
sqlalchemy==2.0.51
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sqlalchemy.exc.InvalidRequestError in pkg:pypi/sqlalchemy@2.0.51",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/sqlalchemy@2.0.51"
  ],
  "symbols": [
    "sqlalchemy.exc.InvalidRequestError"
  ]
}
test/contract.py
import sqlalchemy
from sqlalchemy import MetaData, Table, Column, Integer, String, create_engine, select
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session
from sqlalchemy.exc import SQLAlchemyError, InvalidRequestError

# 1. Verify inheritance and exception representation
assert issubclass(InvalidRequestError, SQLAlchemyError), "InvalidRequestError must be a subclass of SQLAlchemyError"
err = InvalidRequestError("sample error message")
assert str(err) == "sample error message"

# 2. Verify calling session.begin() when transaction is already active raises InvalidRequestError
engine = create_engine("sqlite:///:memory:")
session = Session(engine)
session.begin()
try:
    session.begin()
    raise AssertionError("Expected InvalidRequestError when calling begin() on already begun session")
except InvalidRequestError as exc:
    assert "already begun" in str(exc)
finally:
    session.rollback()
    session.close()

# 3. Verify adding an instance already attached to another session raises InvalidRequestError
class Base(DeclarativeBase):
    pass

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

Base.metadata.create_all(engine)

s1 = Session(engine)
s2 = Session(engine)
user = User(id=1, name="Alice")
s1.add(user)
try:
    s2.add(user)
    raise AssertionError("Expected InvalidRequestError when adding object attached to another session")
except InvalidRequestError as exc:
    assert "already attached to session" in str(exc)
finally:
    s1.close()
    s2.close()

# 4. Verify deleting or refreshing a transient instance not persistent in session raises InvalidRequestError
s3 = Session(engine)
transient_user = User(id=2, name="Bob")
try:
    s3.delete(transient_user)
    raise AssertionError("Expected InvalidRequestError when deleting transient object")
except InvalidRequestError as exc:
    assert "is not persisted" in str(exc)

try:
    s3.refresh(transient_user)
    raise AssertionError("Expected InvalidRequestError when refreshing transient object")
except InvalidRequestError as exc:
    assert "is not persistent within this Session" in str(exc)
finally:
    s3.close()

# 5. Verify defining duplicate Table names in MetaData without extend_existing=True raises InvalidRequestError
md = MetaData()
Table("items", md, Column("id", Integer, primary_key=True))
try:
    Table("items", md, Column("id", Integer, primary_key=True))
    raise AssertionError("Expected InvalidRequestError on duplicate table definition")
except InvalidRequestError as exc:
    assert "already defined for this MetaData instance" in str(exc)

# 6. Verify joining tables without ForeignKey or explicit ON clause raises InvalidRequestError on execute
class Order(Base):
    __tablename__ = "orders"
    id: Mapped[int] = mapped_column(primary_key=True)

Base.metadata.create_all(engine)
s4 = Session(engine)
stmt = select(User).join(Order)
try:
    s4.execute(stmt)
    raise AssertionError("Expected InvalidRequestError on ambiguous join execution")
except InvalidRequestError as exc:
    assert "Don't know how to join" in str(exc)
finally:
    s4.close()

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

Origin Seeder

anonymous