Skip to content

Commit ba599c7

Browse files
authored
chore: Throw a 404 instead of returning defaults if settings does not exist (#6704)
1 parent 7e359ed commit ba599c7

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

frontend/src/components/shared/modals/settings/settings-modal.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { LoadingSpinner } from "../../loading-spinner";
55
import { ModalBackdrop } from "../modal-backdrop";
66
import { SettingsForm } from "./settings-form";
77
import { Settings } from "#/types/settings";
8+
import { DEFAULT_SETTINGS } from "#/services/settings";
89

910
interface SettingsModalProps {
10-
settings: Settings;
11+
settings?: Settings;
1112
onClose: () => void;
1213
}
1314

@@ -38,7 +39,7 @@ export function SettingsModal({ onClose, settings }: SettingsModalProps) {
3839
)}
3940
{aiConfigOptions.data && (
4041
<SettingsForm
41-
settings={settings}
42+
settings={settings || DEFAULT_SETTINGS}
4243
models={aiConfigOptions.data?.models}
4344
agents={aiConfigOptions.data?.agents}
4445
securityAnalyzers={aiConfigOptions.data?.securityAnalyzers}

frontend/src/hooks/query/use-settings.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useQuery } from "@tanstack/react-query";
22
import React from "react";
33
import posthog from "posthog-js";
4-
import { DEFAULT_SETTINGS } from "#/services/settings";
54
import OpenHands from "#/api/open-hands";
65
import { useAuth } from "#/context/auth-context";
76
import { useConfig } from "#/hooks/query/use-config";
@@ -31,10 +30,11 @@ export const useSettings = () => {
3130
const query = useQuery({
3231
queryKey: ["settings"],
3332
queryFn: getSettingsQueryFn,
34-
initialData: DEFAULT_SETTINGS,
35-
staleTime: 0,
36-
retry: false,
3733
enabled: config?.APP_MODE !== "saas" || githubTokenIsSet,
34+
// Only retry if the error is not a 404 because we
35+
// would want to show the modal immediately if the
36+
// settings are not found
37+
retry: (_, error) => error.status !== 404,
3838
meta: {
3939
disableToast: true,
4040
},

openhands/storage/settings/file_settings_store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def load(self) -> Settings | None:
2323
settings = Settings(**kwargs)
2424
return settings
2525
except FileNotFoundError:
26-
return Settings.from_config()
26+
return None
2727

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

0 commit comments

Comments
 (0)