CodeSampleX

Beispiel

sqlalchemy 2.0.51: exc.ArgumentError

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

sha256:61db2a417bf34a0d5b5be76854701edf576ac2e7ad8587b7ed3d74d360a4b12d

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 linux 24 · ubuntu · glibc 2.39 x64 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-05

Fall

HOW
Ziel
verify sqlalchemy.exc.ArgumentError in pkg:pypi/sqlalchemy@2.0.51
Pakete
Symbole
  • sqlalchemy.exc.ArgumentError
Erstellt
2026-09-05T18:54:39Z

Contract

  1. make_url raises sqlalchemy.exc.ArgumentError when given an unparseable URL string
  2. create_engine raises sqlalchemy.exc.ArgumentError when future is explicitly set to False in 2.0
  3. select raises sqlalchemy.exc.ArgumentError when a raw string column expression is passed without text() or column()
  4. Select.where raises sqlalchemy.exc.ArgumentError when a raw string SQL predicate is passed without text()
  5. Session.execute raises sqlalchemy.exc.ArgumentError when a raw string SQL statement is passed without text()
  6. relationship raises sqlalchemy.exc.ArgumentError when both backref and back_populates arguments are provided
  7. sqlalchemy.exc.ArgumentError inherits from SQLAlchemyError and acts as base class for configuration and argument errors

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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.ArgumentError 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.ArgumentError

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:75d3e4337cfc2cde60a6cbb5b3e13f21b818e9aca622da3c69a8d21bd8162766","contract":["make_url raises sqlalchemy.exc.ArgumentError when given an unparseable URL string","create_engine raises sqlalchemy.exc.ArgumentError when future is explicitly set to False in 2.0","select raises sqlalchemy.exc.ArgumentError when a raw string column expression is passed without text() or column()","Select.where raises sqlalchemy.exc.ArgumentError when a raw string SQL predicate is passed without text()","Session.execute raises sqlalchemy.exc.ArgumentError when a raw string SQL statement is passed without text()","relationship raises sqlalchemy.exc.ArgumentError when both backref and back_populates arguments are provided","sqlalchemy.exc.ArgumentError inherits from SQLAlchemyError and acts as base class for configuration and argument errors"],"goal":"verify sqlalchemy.exc.ArgumentError in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.exc.ArgumentError"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"subject":"pkg:pypi/sqlalchemy@2.0.51","symbols":["sqlalchemy.exc.ArgumentError"],"verifierAdapter":"python@1"}
requirements.txt
sqlalchemy==2.0.51
sample.py
"""Demonstration of sqlalchemy.exc.ArgumentError triggers and handling in SQLAlchemy 2.0."""

from typing import Any
from sqlalchemy import Column, ForeignKey, Integer, create_engine, select
from sqlalchemy.engine import make_url
from sqlalchemy.exc import ArgumentError
from sqlalchemy.orm import Session, declarative_base, relationship

Base = declarative_base()


def parse_invalid_url(url_string: str) -> None:
    """Attempt to parse an invalid database URL string, triggering ArgumentError."""
    make_url(url_string)


def create_engine_with_legacy_future_flag(db_url: str = "sqlite:///:memory:") -> None:
    """Attempt to create an engine with future=False in SQLAlchemy 2.0, triggering ArgumentError."""
    create_engine(db_url, future=False)


def build_select_with_raw_string(column_name: str) -> None:
    """Attempt to pass a raw column string directly into select(), triggering ArgumentError."""
    select(column_name)


def filter_query_with_raw_string(predicate: str) -> Any:
    """Attempt to pass a raw SQL string into Select.where(), triggering ArgumentError."""
    return select().where(predicate)


def execute_raw_string_on_session(session: Session, raw_sql: str) -> None:
    """Attempt to execute a raw SQL string on Session without wrapping in text(), triggering ArgumentError."""
    session.execute(raw_sql)


def define_conflicting_relationship() -> None:
    """Attempt to declare an ORM relationship specifying both backref and back_populates."""

    class ParentModel(Base):
        __tablename__ = "sample_parent"
        id = Column(Integer, primary_key=True)
        children = relationship("ChildModel", backref="parent_ref", back_populates="parent_ref")

    class ChildModel(Base):
        __tablename__ = "sample_child"
        id = Column(Integer, primary_key=True)
        parent_id = Column(Integer, ForeignKey("sample_parent.id"))
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sqlalchemy.exc.ArgumentError in pkg:pypi/sqlalchemy@2.0.51",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/sqlalchemy@2.0.51"
  ],
  "symbols": [
    "sqlalchemy.exc.ArgumentError"
  ]
}
test/contract.py
"""Contract verification tests for sqlalchemy.exc.ArgumentError in pkg:pypi/sqlalchemy@2.0.51."""

import os
import sys

# Ensure repository root is on sys.path for local imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from sqlalchemy import create_engine
from sqlalchemy.exc import ArgumentError, SQLAlchemyError
from sqlalchemy.orm import Session
from sample import (
    build_select_with_raw_string,
    create_engine_with_legacy_future_flag,
    define_conflicting_relationship,
    execute_raw_string_on_session,
    filter_query_with_raw_string,
    parse_invalid_url,
)


def test_make_url_invalid_string() -> None:
    """make_url raises sqlalchemy.exc.ArgumentError when given an unparseable URL string."""
    try:
        parse_invalid_url("not_a_valid_database_url")
        assert False, "Expected ArgumentError on malformed database URL string"
    except ArgumentError as exc:
        assert "Could not parse SQLAlchemy URL" in str(exc)
        assert isinstance(exc, ArgumentError)


def test_create_engine_future_false() -> None:
    """create_engine raises sqlalchemy.exc.ArgumentError when future is explicitly set to False in 2.0."""
    try:
        create_engine_with_legacy_future_flag("sqlite:///:memory:")
        assert False, "Expected ArgumentError when passing future=False"
    except ArgumentError as exc:
        assert "The 'future' parameter passed to create_engine() may only be set to True" in str(exc)
        assert isinstance(exc, ArgumentError)


def test_select_raw_string_column() -> None:
    """select raises sqlalchemy.exc.ArgumentError when a raw string column expression is passed without text() or column()."""
    try:
        build_select_with_raw_string("users")
        assert False, "Expected ArgumentError when passing raw string to select()"
    except ArgumentError as exc:
        assert "Textual column expression 'users' should be explicitly declared with text" in str(exc)
        assert isinstance(exc, ArgumentError)


def test_select_where_raw_string() -> None:
    """Select.where raises sqlalchemy.exc.ArgumentError when a raw string SQL predicate is passed without text()."""
    try:
        filter_query_with_raw_string("id = 1")
        assert False, "Expected ArgumentError when passing raw string to Select.where()"
    except ArgumentError as exc:
        assert "Textual SQL expression 'id = 1' should be explicitly declared as text" in str(exc)
        assert isinstance(exc, ArgumentError)


def test_session_execute_raw_string() -> None:
    """Session.execute raises sqlalchemy.exc.ArgumentError when a raw string SQL statement is passed without text()."""
    engine = create_engine("sqlite:///:memory:")
    with Session(engine) as session:
        try:
            execute_raw_string_on_session(session, "SELECT 1")
            assert False, "Expected ArgumentError when executing raw SQL string on Session"
        except ArgumentError as exc:
            assert "Textual SQL expression 'SELECT 1' should be explicitly declared as text" in str(exc)
            assert isinstance(exc, ArgumentError)


def test_relationship_conflicting_backref_and_back_populates() -> None:
    """relationship raises sqlalchemy.exc.ArgumentError when both backref and back_populates arguments are provided."""
    try:
        define_conflicting_relationship()
        assert False, "Expected ArgumentError when providing mutually exclusive backref and back_populates"
    except ArgumentError as exc:
        assert "backref and back_populates keyword arguments are mutually exclusive" in str(exc)
        assert isinstance(exc, ArgumentError)


def test_argument_error_hierarchy() -> None:
    """sqlalchemy.exc.ArgumentError inherits from SQLAlchemyError and acts as base class for configuration and argument errors."""
    assert issubclass(ArgumentError, SQLAlchemyError)
    assert issubclass(ArgumentError, Exception)
    assert hasattr(ArgumentError, "__doc__")


def main() -> int:
    test_make_url_invalid_string()
    test_create_engine_future_false()
    test_select_raw_string_column()
    test_select_where_raw_string()
    test_session_execute_raw_string()
    test_relationship_conflicting_backref_and_back_populates()
    test_argument_error_hierarchy()
    print("All sqlalchemy.exc.ArgumentError contract assertions passed.")
    return 0


if __name__ == "__main__":
    sys.exit(main())

Ursprungs-Seeder

anonym