fix: keep migration and blocker SQL postgres-safe
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_alembic_revision_ids_fit_version_num_column():
|
||||
versions = Path(__file__).parents[1] / "alembic" / "versions"
|
||||
too_long = []
|
||||
for path in versions.glob("*.py"):
|
||||
spec = importlib.util.spec_from_file_location(f"migration_{path.stem}", path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
revision = getattr(module, "revision", None)
|
||||
if revision is not None and len(revision) > 32:
|
||||
too_long.append((path.name, revision, len(revision)))
|
||||
assert too_long == []
|
||||
@@ -1,10 +1,11 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from central.app.audit import record_audit
|
||||
from central.app.blocked_products import upsert_blocker
|
||||
from central.app.control_plane import dashboard_summary, list_blockers, list_installations, list_jobs
|
||||
from central.app.control_plane import _blocker_breakdown_query, dashboard_summary, list_blockers, list_installations, list_jobs
|
||||
from central.app.events import record_event
|
||||
from central.app.models import Agent, AgentSnapshot, AuditEvent, BlockedProduct, Installation, Job, Tenant
|
||||
from central.tests.test_control_plane import setup_db
|
||||
@@ -310,3 +311,13 @@ def test_lowercase_required_blocker_field_reaches_attention_candidates():
|
||||
attention = dashboard_summary(session, now=NOW)["attention_items"]
|
||||
|
||||
assert any(item["link"] == f"/blockers/{blocker.id}" for item in attention)
|
||||
|
||||
|
||||
def test_blocker_breakdown_query_groups_on_same_postgres_expression():
|
||||
from sqlalchemy import select
|
||||
|
||||
query = select(BlockedProduct, Tenant).join(Tenant, Tenant.id == BlockedProduct.tenant_id)
|
||||
sql = str(_blocker_breakdown_query(query).compile(dialect=postgresql.dialect()))
|
||||
|
||||
assert "GROUP BY blocked_products.field" in sql
|
||||
assert "GROUP BY coalesce" not in sql
|
||||
|
||||
Reference in New Issue
Block a user