Skip to content

Provider strings are not correctly validated for empty strings #1394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Update empty provider endpoint names with placeholders

Revision ID: 736fb0c10480
Revises: e4c05d7591a8
Create Date: 2025-05-01 19:17:41.766575

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "736fb0c10480"
down_revision: Union[str, None] = "e4c05d7591a8"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.execute(
"""
UPDATE provider_endpoints
SET name = 'placeholder_' || id
WHERE name = ''
"""
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# Downgrading is complex as we don't know which names were placeholders.
# We'll leave this empty, assuming the model validation change is permanent.
pass
# ### end Alembic commands ###
5 changes: 3 additions & 2 deletions src/codegate/api/v1_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import datetime
import json
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from typing import Annotated, Any, Dict, List, Optional, Union

import pydantic
from pydantic import Field

import codegate.muxing.models as mux_models
from codegate.db import models as db_models
Expand Down Expand Up @@ -268,7 +269,7 @@ class ProviderEndpoint(pydantic.BaseModel):

# This will be set on creation
id: Optional[str] = ""
name: str
name: Annotated[str, Field(min_length=3)]
description: str = ""
provider_type: db_models.ProviderType
endpoint: str = "" # Some providers have defaults we can leverage
Expand Down
Loading