示例
sqlalchemy 2.0.51: exc.InvalidRequestError
已验证示例 — pypi sqlalchemy 2.0.51: exc.InvalidRequestError. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: InvalidRequestError is a subclass of…
sha256:390ec80d1882d95d4bf8d7ff16d396deb59e90c5098898bfbbd2056e5f615a06
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
python linux 24 · ubuntu · glibc 2.39 x64 python python pip
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify sqlalchemy.exc.InvalidRequestError in pkg:pypi/sqlalchemy@2.0.51
- 符号
-
- sqlalchemy.exc.InvalidRequestError
- 环境
- python
- 创建时间
- 2026-09-05T23:24:47Z
契约
- 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.
文件
- NOTES.md
- PROMPT.md
- csx.json
- requirements.txt
- spec.json
- test/contract.py
源代码
# 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`.
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.
{"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"}
sqlalchemy==2.0.51
{
"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"
]
}
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")
原始种子者
匿名