1. backend/app/models/network_diagram.py — `nodes` and `edges` columns
used `server_default="'[]'"` (a Python string), which SQLAlchemy
wraps in single quotes when generating DDL, producing
`JSONB DEFAULT '''[]'''` — invalid JSON. Switch to
`server_default=text("'[]'::jsonb")` so the literal is passed through
and the table can actually be created. Surfaced on every CI run as
`asyncpg.exceptions.InvalidTextRepresentationError: invalid input
syntax for type json` at fixture setup time, cascading hundreds of
test errors.
2. backend/tests/conftest.py — drop the deprecated session-scoped
`event_loop` fixture. Since pytest-asyncio 0.23+, the plugin manages
the loop itself; redefining it with a session scope but never
`set_event_loop()`-ing it left the loop dangling, so any test that
called `asyncio.run()` (e.g. `test_tasks_are_isolated`) closed the
process loop and broke the next async test in the module —
`test_require_tenant_context_raises_403_when_no_account` was the
visible casualty in the CI logs.
Verified locally:
- `pytest tests/test_uploads.py::test_upload_success` — was setup-error
on `network_diagrams` DDL; now passes.
- `pytest tests/test_tenant_context.py` — was 1 fail / 3 pass; now 4/4.
Both are real bugs, not test infrastructure churn. Pre-existing on
main; not introduced here.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
"""Network diagram model."""
|
|
import uuid
|
|
from datetime import datetime, timezone
|
|
from typing import Any, TYPE_CHECKING
|
|
|
|
from sqlalchemy import String, Text, Boolean, DateTime, ForeignKey, text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
|
|
from app.core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.user import User
|
|
|
|
|
|
class NetworkDiagram(Base):
|
|
"""A network topology diagram scoped to one account."""
|
|
__tablename__ = "network_diagrams"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
account_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("accounts.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
client_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
asset_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
nodes: Mapped[list[dict[str, Any]]] = mapped_column(JSONB, nullable=False, server_default=text("'[]'::jsonb"))
|
|
edges: Mapped[list[dict[str, Any]]] = mapped_column(JSONB, nullable=False, server_default=text("'[]'::jsonb"))
|
|
thumbnail_url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
is_archived: Mapped[bool] = mapped_column(
|
|
Boolean, nullable=False, default=False,
|
|
)
|
|
created_by: Mapped[uuid.UUID | None] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("users.id"),
|
|
nullable=True,
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc),
|
|
)
|
|
|
|
creator: Mapped["User | None"] = relationship("User", foreign_keys=[created_by])
|