Skip to content

Commit 0384db3

Browse files
authored
Fix: Reload context on config change (#2269)
1 parent 840396e commit 0384db3

File tree

13 files changed

+98
-51
lines changed

13 files changed

+98
-51
lines changed

sqlmesh/core/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def reload_needed(self) -> bool:
156156
True if a modification is found; False otherwise
157157
"""
158158
return any(
159-
path.stat().st_mtime > initial_mtime
159+
not path.exists() or path.stat().st_mtime > initial_mtime
160160
for path, initial_mtime in self._path_mtimes.items()
161161
)
162162

web/client/src/library/components/documentation/Documentation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const Documentation = function Documentation({
4747
return () => {
4848
cancelRequestModel()
4949
}
50-
}, [model.hash])
50+
}, [model.name, model.hash])
5151

5252
return (
5353
<Container>

web/client/src/library/components/editor/EditorInspector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ function FormDiffModel({
584584
void getDiff().then(({ data }) => {
585585
setPreviewDiff(data)
586586
})
587-
}, [model.hash])
587+
}, [model.name, model.hash])
588588

589589
useEffect(() => {
590590
return () => {

web/client/src/library/components/fileExplorer/Directory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Directory = function Directory({
3232
const [isDraggable, setIsDraggable] = useState(false)
3333

3434
const attrs = useLongPress(() => setIsDraggable(true), {
35-
threshold: 500,
35+
threshold: 50,
3636
onFinish() {
3737
setIsDraggable(false)
3838
},

web/client/src/library/components/fileExplorer/File.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function File({
3535
const [isDraggable, setIsDraggable] = useState(false)
3636

3737
const attrs = useLongPress(() => setIsDraggable(true), {
38-
threshold: 500,
38+
threshold: 50,
3939
onFinish() {
4040
setIsDraggable(false)
4141
},

web/client/src/library/components/graph/ModelLineage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default function ModelLineage({
118118
setMainNode(undefined)
119119
setHighlightedNodes({})
120120
}
121-
}, [model.hash])
121+
}, [model.name, model.hash])
122122

123123
useEffect(() => {
124124
Object.keys(modelLineage ?? {}).forEach(modelName => {

web/client/src/library/components/loading/LoadingStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function LoadingStatus({
99
return (
1010
<Loading className="inline-block">
1111
<Spinner className="w-3 h-3 border border-neutral-10 mr-2" />
12-
<span className="inline-block text-xs">{children}</span>
12+
<span className="inline-block text-xs whitespace-nowrap">{children}</span>
1313
</Loading>
1414
)
1515
}

web/client/src/library/pages/root/Navigation.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ export default function PageNavigation(): JSX.Element {
1414
return (
1515
<div
1616
className={clsx(
17-
'min-w-[10rem] px-2 min-h-8 max-h-8 w-full flex items-center',
17+
'relative min-w-[10rem] px-2 min-h-8 max-h-8 w-full flex items-center',
1818
modules.showHistoryNavigation ? 'justify-between' : 'justify-end',
1919
)}
2020
>
2121
{modules.showHistoryNavigation && <HistoryNavigation />}
22-
{isFetchingModels ? (
23-
<LoadingStatus>Loading Models...</LoadingStatus>
24-
) : (
25-
modules.hasPlans && <EnvironmentDetails />
22+
{isFetchingModels && (
23+
<div className="absolute w-full h-full flex justify-center items-center z-10 bg-transparent-20 backdrop-blur-lg">
24+
<LoadingStatus>Loading Models...</LoadingStatus>
25+
</div>
2626
)}
27+
{modules.hasPlans && <EnvironmentDetails />}
2728
{modules.hasErrors && <ReportErrors />}
2829
</div>
2930
)

web/server/api/endpoints/directories.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@
55
from fastapi import APIRouter, Body, Depends, HTTPException, Response, status
66
from starlette.status import HTTP_404_NOT_FOUND
77

8-
from sqlmesh.core.context import Context
98
from web.server import models
109
from web.server.exceptions import ApiException
11-
from web.server.settings import Settings, get_context, get_settings
10+
from web.server.settings import Settings, get_settings
1211
from web.server.utils import replace_file, validate_path
1312

1413
router = APIRouter()
1514

1615

1716
@router.post("/{path:path}", response_model=models.Directory)
1817
async def write_directory(
19-
response: Response,
2018
path: str = Depends(validate_path),
2119
new_path: t.Optional[str] = Body(None, embed=True),
2220
settings: Settings = Depends(get_settings),
23-
context: Context = Depends(get_context),
2421
) -> models.Directory:
2522
"""Create or rename a directory."""
2623
if new_path:
27-
validate_path(new_path, context)
24+
new_path = await validate_path(new_path, settings)
2825
replace_file(settings.project_path / path, settings.project_path / new_path)
2926
return models.Directory(name=os.path.basename(new_path), path=new_path)
3027

web/server/api/endpoints/files.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,9 @@
2525

2626

2727
@router.get("", response_model=models.Directory)
28-
def get_files(
29-
context: t.Optional[Context] = Depends(get_context),
30-
settings: Settings = Depends(get_settings),
31-
) -> models.Directory:
28+
async def get_files(settings: Settings = Depends(get_settings)) -> models.Directory:
3229
"""Get all project files."""
33-
return _get_directory(
34-
path=settings.project_path,
35-
settings=settings,
36-
context=context,
37-
)
30+
return await _get_directory(settings.project_path, settings)
3831

3932

4033
@router.get("/{path:path}", response_model=models.File)
@@ -54,21 +47,26 @@ def get_file(
5447
@router.post("/{path:path}", response_model=t.Optional[models.File])
5548
async def write_file(
5649
response: Response,
50+
path: str = Depends(validate_path),
5751
content: str = Body("", embed=True),
5852
new_path: t.Optional[str] = Body(None, embed=True),
59-
path: str = Depends(validate_path),
6053
settings: Settings = Depends(get_settings),
61-
context: Context = Depends(get_context),
54+
context: t.Optional[Context] = Depends(get_context),
6255
) -> t.Optional[models.File]:
6356
"""Create, update, or rename a file."""
6457
path_or_new_path = path
6558
if new_path:
66-
path_or_new_path = validate_path(new_path, context)
59+
path_or_new_path = await validate_path(new_path, settings)
6760
replace_file(settings.project_path / path, settings.project_path / path_or_new_path)
6861
else:
6962
full_path = settings.project_path / path
70-
config = context.config_for_path(Path(path_or_new_path))
71-
if config.ui.format_on_save and content and Path(path_or_new_path).suffix == ".sql":
63+
config = context.config_for_path(Path(path_or_new_path)) if context else None
64+
if (
65+
config
66+
and config.ui.format_on_save
67+
and content
68+
and Path(path_or_new_path).suffix == ".sql"
69+
):
7270
format_file_status = models.FormatFileStatus(
7371
status=models.Status.INIT, path=path_or_new_path
7472
)
@@ -120,11 +118,8 @@ async def delete_file(
120118
)
121119

122120

123-
def _get_directory(
124-
path: str | Path,
125-
settings: Settings,
126-
context: t.Optional[Context] = None,
127-
) -> models.Directory:
121+
async def _get_directory(path: str | Path, settings: Settings) -> models.Directory:
122+
context = await get_context(settings)
128123
ignore_patterns = context.config.ignore_patterns if context else c.IGNORE_PATTERNS
129124

130125
def walk_path(

0 commit comments

Comments
 (0)