mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
fix(settings): search_provider_id NULL scan failure
The ::text cast on search_providers.id prevented sqlc from inferring nullability via LEFT JOIN, generating a non-nullable string field that crashes when the bot has no search provider bound.
This commit is contained in:
@@ -7,7 +7,7 @@ SELECT
|
|||||||
chat_models.model_id AS chat_model_id,
|
chat_models.model_id AS chat_model_id,
|
||||||
memory_models.model_id AS memory_model_id,
|
memory_models.model_id AS memory_model_id,
|
||||||
embedding_models.model_id AS embedding_model_id,
|
embedding_models.model_id AS embedding_model_id,
|
||||||
search_providers.id::text AS search_provider_id
|
search_providers.id AS search_provider_id
|
||||||
FROM bots
|
FROM bots
|
||||||
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
|
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
|
||||||
LEFT JOIN models AS memory_models ON memory_models.id = bots.memory_model_id
|
LEFT JOIN models AS memory_models ON memory_models.id = bots.memory_model_id
|
||||||
@@ -37,7 +37,7 @@ SELECT
|
|||||||
chat_models.model_id AS chat_model_id,
|
chat_models.model_id AS chat_model_id,
|
||||||
memory_models.model_id AS memory_model_id,
|
memory_models.model_id AS memory_model_id,
|
||||||
embedding_models.model_id AS embedding_model_id,
|
embedding_models.model_id AS embedding_model_id,
|
||||||
search_providers.id::text AS search_provider_id
|
search_providers.id AS search_provider_id
|
||||||
FROM updated
|
FROM updated
|
||||||
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
|
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
|
||||||
LEFT JOIN models AS memory_models ON memory_models.id = updated.memory_model_id
|
LEFT JOIN models AS memory_models ON memory_models.id = updated.memory_model_id
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ SELECT
|
|||||||
chat_models.model_id AS chat_model_id,
|
chat_models.model_id AS chat_model_id,
|
||||||
memory_models.model_id AS memory_model_id,
|
memory_models.model_id AS memory_model_id,
|
||||||
embedding_models.model_id AS embedding_model_id,
|
embedding_models.model_id AS embedding_model_id,
|
||||||
search_providers.id::text AS search_provider_id
|
search_providers.id AS search_provider_id
|
||||||
FROM bots
|
FROM bots
|
||||||
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
|
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
|
||||||
LEFT JOIN models AS memory_models ON memory_models.id = bots.memory_model_id
|
LEFT JOIN models AS memory_models ON memory_models.id = bots.memory_model_id
|
||||||
@@ -55,7 +55,7 @@ type GetSettingsByBotIDRow struct {
|
|||||||
ChatModelID pgtype.Text `json:"chat_model_id"`
|
ChatModelID pgtype.Text `json:"chat_model_id"`
|
||||||
MemoryModelID pgtype.Text `json:"memory_model_id"`
|
MemoryModelID pgtype.Text `json:"memory_model_id"`
|
||||||
EmbeddingModelID pgtype.Text `json:"embedding_model_id"`
|
EmbeddingModelID pgtype.Text `json:"embedding_model_id"`
|
||||||
SearchProviderID string `json:"search_provider_id"`
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetSettingsByBotID(ctx context.Context, id pgtype.UUID) (GetSettingsByBotIDRow, error) {
|
func (q *Queries) GetSettingsByBotID(ctx context.Context, id pgtype.UUID) (GetSettingsByBotIDRow, error) {
|
||||||
@@ -96,7 +96,7 @@ SELECT
|
|||||||
chat_models.model_id AS chat_model_id,
|
chat_models.model_id AS chat_model_id,
|
||||||
memory_models.model_id AS memory_model_id,
|
memory_models.model_id AS memory_model_id,
|
||||||
embedding_models.model_id AS embedding_model_id,
|
embedding_models.model_id AS embedding_model_id,
|
||||||
search_providers.id::text AS search_provider_id
|
search_providers.id AS search_provider_id
|
||||||
FROM updated
|
FROM updated
|
||||||
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
|
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
|
||||||
LEFT JOIN models AS memory_models ON memory_models.id = updated.memory_model_id
|
LEFT JOIN models AS memory_models ON memory_models.id = updated.memory_model_id
|
||||||
@@ -123,7 +123,7 @@ type UpsertBotSettingsRow struct {
|
|||||||
ChatModelID pgtype.Text `json:"chat_model_id"`
|
ChatModelID pgtype.Text `json:"chat_model_id"`
|
||||||
MemoryModelID pgtype.Text `json:"memory_model_id"`
|
MemoryModelID pgtype.Text `json:"memory_model_id"`
|
||||||
EmbeddingModelID pgtype.Text `json:"embedding_model_id"`
|
EmbeddingModelID pgtype.Text `json:"embedding_model_id"`
|
||||||
SearchProviderID string `json:"search_provider_id"`
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsParams) (UpsertBotSettingsRow, error) {
|
func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsParams) (UpsertBotSettingsRow, error) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
|
||||||
"github.com/memohai/memoh/internal/db"
|
"github.com/memohai/memoh/internal/db"
|
||||||
@@ -175,13 +176,15 @@ func normalizeBotSettingsFields(
|
|||||||
chatModelID pgtype.Text,
|
chatModelID pgtype.Text,
|
||||||
memoryModelID pgtype.Text,
|
memoryModelID pgtype.Text,
|
||||||
embeddingModelID pgtype.Text,
|
embeddingModelID pgtype.Text,
|
||||||
searchProviderID string,
|
searchProviderID pgtype.UUID,
|
||||||
) Settings {
|
) Settings {
|
||||||
settings := normalizeBotSetting(maxContextLoadTime, language, allowGuest)
|
settings := normalizeBotSetting(maxContextLoadTime, language, allowGuest)
|
||||||
settings.ChatModelID = strings.TrimSpace(chatModelID.String)
|
settings.ChatModelID = strings.TrimSpace(chatModelID.String)
|
||||||
settings.MemoryModelID = strings.TrimSpace(memoryModelID.String)
|
settings.MemoryModelID = strings.TrimSpace(memoryModelID.String)
|
||||||
settings.EmbeddingModelID = strings.TrimSpace(embeddingModelID.String)
|
settings.EmbeddingModelID = strings.TrimSpace(embeddingModelID.String)
|
||||||
settings.SearchProviderID = strings.TrimSpace(searchProviderID)
|
if searchProviderID.Valid {
|
||||||
|
settings.SearchProviderID = uuid.UUID(searchProviderID.Bytes).String()
|
||||||
|
}
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user