Enforce SQLAlchemy-only database connections and Alembic-only schema changes
Maintainer antworten meist innerhalb von 3 Tagen
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Start with the existing rules registry and pytest guards, then inspect policyengine_api/data/v2/catalog/publication_staging.py to understand the two stated exceptions. Add a guard covering the specified code paths, proof fixtures, CI wiring in the existing test job, and guidance in docs/engineering/skills/alembic-migrations.md. Done means the guard rejects direct relational driver use and non-Alembic persistent schema changes, accepts only the exact exceptions, and its tests run in CI. Pull request #3979 is already open.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem
The Public API opens every relational database connection through SQLAlchemy today: API v1 builds its Cloud SQL engine in policyengine_api/data/orm.py (the Cloud SQL connector is passed to create_engine as creator=), and API v2 builds its SQLModel engine from a postgresql+psycopg URL in policyengine_api/data/v2/database.py. Schema changes go through the autogenerated Alembic revisions under migrations/v1 and migrations/v2.
Nothing enforces either of these. The rules registry has related rules, but none of them forbids:
- a direct driver connection such as
psycopg.connect(...),pymysql.connect(...)orsqlite3.connect(...), or use of the driver connection beneath SQLAlchemy, in application code, scripts or CI code.api.data.runtime-sql-confinedonly confines raw SQL to the data-access layer, andapi.services.no-direct-queriesonly covers services; - a schema change outside Alembic, such as
metadata.create_all(engine),Table.create(...),op.*outsidemigrations/, orCREATE/ALTER/DROP/TRUNCATESQL text.api.migration.alembic-autogenerated-onlyis doc-only, andapi.migration.alembic-v1-qualified/api.migration.alembic-v2-qualifiedcheck the revisions, not the code around them.
Both have happened before: the Stage 12 provisioning script (removed in d8bd72191) opened psycopg connections directly, and the local database bootstrap added in 6c7804100 called V1Base.metadata.create_all at runtime.
Proposed rule
Register an enforced rule, api.data.sqlalchemy-and-alembic-only: code connects to relational databases only through SQLAlchemy engines, connections and sessions, never by calling a database driver directly, and changes persistent schema only through Alembic revisions.
- Enforce it with a pytest guard that parses non-test code (
policyengine_api/,scripts/,migrations/,.github/, excluding tests and the generated revisions undermigrations/*/versions/). - Declare the two current exceptions exactly, both in
policyengine_api/data/v2/catalog/publication_staging.py:COPY ... FROM STDINthrough the psycopg connection beneath a SQLAlchemyConnection, because SQLAlchemy has no COPY API;STAGING_METADATA.create_allforTEMPORARYtables that Postgres drops at commit, which are not persistent schema.
- The guard should fail if either exception grows or is no longer needed.
- Redis (
policyengine_api/runtime_cache/) is a key-value cache, not a relational database, and is out of scope. - Add proof fixtures, CI wiring through the existing
testjob, and a section indocs/engineering/skills/alembic-migrations.md.
- Vorherrschende Sprache
- Python
- Sterne
- 18
- Forks
- 33
- Ø Merge
- 2 T. 15 Std.
- Gemergte PRs (30 T.)
- 35
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus PolicyEngine/policyengine-api
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
PolicyEngine/policyengine-api#3911 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
PolicyEngine/policyengine-api#3910 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Let a saved reform or household point at a new v2 policy or household without changing its IDEvtl. vergeben @anth-volk hat das heute übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
PolicyEngine/policyengine-api#4004 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Releases do not check that each environment calls its own simulation serviceEvtl. vergeben @anth-volk hat das heute übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 46/100
PolicyEngine/policyengine-api#4002 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 18/100
PolicyEngine/policyengine-api#4000 ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in PolicyEngine/policyengine-api
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
volcengine/OpenViking#6445 ·
Maintainer antworten meist innerhalb von 1 Tag
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedEvtl. vergeben @ManyaJain111 hat das heute übernommen. Offenbug enhancement possible-duplicate
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
AOSSIE-Org/PictoPy#1637 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
deepspeedai/DeepSpeed#8884 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
flagos-ai/FlagQuantum#718 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug CI-failure high priority
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 86/100
vllm-project/afd-plugin#483 ·
Maintainer antworten meist innerhalb von 1 Tag