Skip to content
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ import requests
r = requests.post("http://localhost:8000/submit", json={"task": "add", "args": [3, 4]})
```

The sync and async server handlers accept the same submit options.

Endpoints:

| Method | Path | Description |
Expand Down
14 changes: 13 additions & 1 deletion src/cashet/_client_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import os
from collections.abc import Callable
from collections.abc import Callable, Mapping
from datetime import timedelta
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -85,6 +85,18 @@ def resolve_status(status: TaskStatus | str | None) -> TaskStatus | None:
return status


def resolve_submit_options(
data: Mapping[str, Any],
) -> tuple[bool, dict[str, str], int, bool, Any, Any]:
cache = data.get("cache") or True
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 High cache option overrides explicit false to true

The shared helper uses data.get("cache") or True, which treats a client-supplied false as falsy and replaces it with True. The original inline code used data.get("cache", True), which correctly preserved an explicit False. This silently re-enables caching when the client explicitly requested no caching, potentially returning stale results.

Suggested change
cache = data.get("cache") or True
cache = data.get("cache", True)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'm glad the review helped. Once you apply the fix to use data.get("cache", True), the caching behavior will correctly respect an explicit False.

tags = data.get("tags") or {}
retries = data.get("retries", 0)
force = data.get("force", False)
timeout = data.get("timeout")
ttl = data.get("ttl")
return cache, tags, retries, force, timeout, ttl


async def load_result(commit: Commit, store: AsyncStore, serializer: Serializer) -> Any:
if commit.output_ref is None:
return None
Expand Down
15 changes: 3 additions & 12 deletions src/cashet/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from starlette.responses import JSONResponse
from starlette.routing import Route

from cashet._client_base import resolve_submit_options
from cashet.async_client import AsyncClient
from cashet.client import Client

Expand Down Expand Up @@ -198,12 +199,7 @@ async def _async_submit(request: Request) -> JSONResponse:
if error is not None:
return error

cache = data.get("cache", True)
tags = data.get("tags", {})
retries = data.get("retries", 0)
force = data.get("force", False)
timeout = data.get("timeout")
ttl = data.get("ttl")
cache, tags, retries, force, timeout, ttl = resolve_submit_options(data)

start = time.perf_counter()
try:
Expand Down Expand Up @@ -404,12 +400,7 @@ async def _submit(request: Request) -> JSONResponse:
if error is not None:
return error

cache = data.get("cache", True)
tags = data.get("tags", {})
retries = data.get("retries", 0)
force = data.get("force", False)
timeout = data.get("timeout")
ttl = data.get("ttl")
cache, tags, retries, force, timeout, ttl = resolve_submit_options(data)

start = time.perf_counter()

Expand Down
Loading