Skip to content
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

chore: Throw a 404 instead of returning defaults if settings does not exist #6704

Merged
merged 3 commits into from
Feb 12, 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
Expand Up @@ -5,9 +5,10 @@ import { LoadingSpinner } from "../../loading-spinner";
import { ModalBackdrop } from "../modal-backdrop";
import { SettingsForm } from "./settings-form";
import { Settings } from "#/types/settings";
import { DEFAULT_SETTINGS } from "#/services/settings";

interface SettingsModalProps {
settings: Settings;
settings?: Settings;
onClose: () => void;
}

Expand Down Expand Up @@ -38,7 +39,7 @@ export function SettingsModal({ onClose, settings }: SettingsModalProps) {
)}
{aiConfigOptions.data && (
<SettingsForm
settings={settings}
settings={settings || DEFAULT_SETTINGS}
models={aiConfigOptions.data?.models}
agents={aiConfigOptions.data?.agents}
securityAnalyzers={aiConfigOptions.data?.securityAnalyzers}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/hooks/query/use-settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import React from "react";
import posthog from "posthog-js";
import { DEFAULT_SETTINGS } from "#/services/settings";
import OpenHands from "#/api/open-hands";
import { useAuth } from "#/context/auth-context";
import { useConfig } from "#/hooks/query/use-config";
Expand Down Expand Up @@ -31,10 +30,11 @@ export const useSettings = () => {
const query = useQuery({
queryKey: ["settings"],
queryFn: getSettingsQueryFn,
initialData: DEFAULT_SETTINGS,
staleTime: 0,
retry: false,
enabled: config?.APP_MODE !== "saas" || githubTokenIsSet,
// Only retry if the error is not a 404 because we
// would want to show the modal immediately if the
// settings are not found
retry: (_, error) => error.status !== 404,
meta: {
disableToast: true,
},
Expand Down
2 changes: 1 addition & 1 deletion openhands/storage/settings/file_settings_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def load(self) -> Settings | None:
settings = Settings(**kwargs)
return settings
except FileNotFoundError:
return Settings.from_config()
return None

async def store(self, settings: Settings):
json_str = settings.model_dump_json(context={'expose_secrets': True})
Expand Down