CodeSampleX

示例

sqlalchemy 2.0.51: exc.ObjectNotExecutableError

已验证示例 — pypi sqlalchemy 2.0.51: exc.ObjectNotExecutableError. contract 在 python 3.12 · linux debian/x64 · docker 上运行并通过: ObjectNotExecutableError inherits…

sha256:92680a5c95b189a07ae79201f3c9fd65d1cb3d6240345053ac8e79c5cbda430a

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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.ObjectNotExecutableError in pkg:pypi/sqlalchemy@2.0.51
包
符号
  • sqlalchemy.exc.ObjectNotExecutableError
环境
python
创建时间
2026-09-05T23:38:29Z

契约

  1. ObjectNotExecutableError inherits from ArgumentError and SQLAlchemyError and preserves the offending target object.
  2. ObjectNotExecutableError supports serialization and deserialization via standard pickle roundtrip.
  3. Connection.execute raises ObjectNotExecutableError when passed a raw SQL string or non-executable object.
  4. Connection.execute raises ObjectNotExecutableError when passed SQL schema elements like Table or Column that do not support direct execution.
  5. Connection.scalar and Connection.scalars raise ObjectNotExecutableError when passed a non-executable object.
  6. Wrapping raw SQL strings with sqlalchemy.text produces an executable construct that executes successfully.

文件

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

下载源代码构件 (tar.gz)

源代码

NOTES.md
# sqlalchemy ObjectNotExecutableError API

This sample pins `sqlalchemy` 2.0.51 and verifies `sqlalchemy.exc.ObjectNotExecutableError`.

In SQLAlchemy 2.0, direct execution of raw SQL strings and non-executable objects is prohibited; executable constructs such as `sqlalchemy.text()` must be used.

The contract verifies:
- `ObjectNotExecutableError` inherits from `ArgumentError` and `SQLAlchemyError` and preserves the offending target object.
- `ObjectNotExecutableError` supports serialization and deserialization via standard pickle roundtrip.
- `Connection.execute` raises `ObjectNotExecutableError` when passed a raw SQL string or non-executable object.
- `Connection.execute` raises `ObjectNotExecutableError` when passed SQL schema elements like `Table` or `Column` that do not support direct execution.
- `Connection.scalar` and `Connection.scalars` raise `ObjectNotExecutableError` when passed a non-executable object.
- Wrapping raw SQL strings with `sqlalchemy.text()` produces an executable construct that executes successfully.
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.ObjectNotExecutableError 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.ObjectNotExecutableError

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:d7a3a14145d3ee96a87dc92ea2b801e9cac4dc87b965be86d8b3d8541875ce48","contract":["ObjectNotExecutableError inherits from ArgumentError and SQLAlchemyError and preserves the offending target object.","ObjectNotExecutableError supports serialization and deserialization via standard pickle roundtrip.","Connection.execute raises ObjectNotExecutableError when passed a raw SQL string or non-executable object.","Connection.execute raises ObjectNotExecutableError when passed SQL schema elements like Table or Column that do not support direct execution.","Connection.scalar and Connection.scalars raise ObjectNotExecutableError when passed a non-executable object.","Wrapping raw SQL strings with sqlalchemy.text produces an executable construct that executes successfully."],"goal":"verify sqlalchemy.exc.ObjectNotExecutableError in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.exc.ObjectNotExecutableError"]},"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.ObjectNotExecutableError"],"verifierAdapter":"python@1"}
requirements.txt
sqlalchemy==2.0.51
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sqlalchemy.exc.ObjectNotExecutableError in pkg:pypi/sqlalchemy@2.0.51",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/sqlalchemy@2.0.51"
  ],
  "symbols": [
    "sqlalchemy.exc.ObjectNotExecutableError"
  ]
}
test/contract.py
import pickle
import sqlalchemy
from sqlalchemy import create_engine, text, Table, Column, Integer, MetaData
from sqlalchemy.exc import ObjectNotExecutableError, ArgumentError, SQLAlchemyError

# 1. Class hierarchy and direct instantiation
err = ObjectNotExecutableError("SELECT 1")
assert isinstance(err, ArgumentError), f"Expected ArgumentError, got {type(err)}"
assert isinstance(err, SQLAlchemyError), f"Expected SQLAlchemyError, got {type(err)}"
assert err.target == "SELECT 1"
assert "Not an executable object: 'SELECT 1'" in str(err)

# 2. Pickle / unpickle roundtrip support via __reduce__
dumped = pickle.dumps(err)
loaded = pickle.loads(dumped)
assert isinstance(loaded, ObjectNotExecutableError)
assert loaded.target == "SELECT 1"
assert str(loaded) == str(err)

# 3. Connection.execute raises ObjectNotExecutableError for non-executable targets
engine = create_engine("sqlite:///:memory:")

with engine.connect() as conn:
    # Raw SQL string
    try:
        conn.execute("SELECT 1")
        raise AssertionError("Expected ObjectNotExecutableError for raw string in conn.execute")
    except ObjectNotExecutableError as e:
        assert e.target == "SELECT 1"
        assert "Not an executable object" in str(e)

    # Non-clauseelement types (int, list, dict)
    for invalid_target in [123, [1, 2], {"key": "value"}]:
        try:
            conn.execute(invalid_target)
            raise AssertionError(f"Expected ObjectNotExecutableError for {invalid_target}")
        except ObjectNotExecutableError as e:
            assert e.target == invalid_target

    # ClauseElements that do not support direct execution (Table, Column)
    metadata = MetaData()
    test_table = Table("items", metadata, Column("id", Integer, primary_key=True))
    try:
        conn.execute(test_table)
        raise AssertionError("Expected ObjectNotExecutableError for Table object")
    except ObjectNotExecutableError as e:
        assert e.target is test_table

    try:
        conn.execute(test_table.c.id)
        raise AssertionError("Expected ObjectNotExecutableError for Column object")
    except ObjectNotExecutableError as e:
        assert e.target is test_table.c.id

    # 4. Connection.scalar and Connection.scalars raise ObjectNotExecutableError
    try:
        conn.scalar("SELECT 1")
        raise AssertionError("Expected ObjectNotExecutableError for raw string in conn.scalar")
    except ObjectNotExecutableError as e:
        assert e.target == "SELECT 1"

    try:
        conn.scalars("SELECT 1")
        raise AssertionError("Expected ObjectNotExecutableError for raw string in conn.scalars")
    except ObjectNotExecutableError as e:
        assert e.target == "SELECT 1"

    # 5. Wrapping raw SQL with text() creates an Executable and succeeds
    res_exec = conn.execute(text("SELECT 1")).scalar()
    assert res_exec == 1

    res_scalar = conn.scalar(text("SELECT 2"))
    assert res_scalar == 2

    res_scalars = conn.scalars(text("SELECT 3")).one()
    assert res_scalars == 3

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

原始种子者

匿名