SShortSingh.
Back to feed

Why None Is Not Enough: Sentinel Values for PATCH Updates in Python

0
·6 views

A recent Hacker News discussion on sentinel values in Python prompted the author to recall a production bug from an update function that used None to mean both "not provided" and "clear the value." The problem surfaces clearly in PATCH APIs, where a field can be absent, explicitly null, or set to a value, and a plain None default cannot distinguish the first two cases. The article reviews the common object()-based sentinel and points out its drawbacks: an unhelpful repr, unreliable copying and pickling, and poor type-checker support. It then proposes an Enum-based sentinel that keeps a readable repr, survives deepcopy and pickle as a singleton, and lets type checkers narrow the type correctly.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Quality events lose their risk rationale before effectiveness review, weakening CAPA traceability

A labeling discrepancy involving two label versions during finished-unit release reached final effectiveness review with a seemingly complete record, but an independent reviewer could not easily trace the original risk rationale. The affected units were contained, labeling was corrected, verification instructions were strengthened, and staff were retrained, all reasonable steps. The core problem was not missing records but the absence of a connected evidence chain linking the original event assessment to the final conclusion. The article argues that a quality event should not automatically become a CAPA, and that the rationale connecting event scope, risk assessment, escalation decisions, root cause, and action effectiveness must be formally documented. It frames this as a traceability problem tied to ISO 13485:2016, which requires corrective action review but prescribes no specific format.

0
ProgrammingDEV Community ·

Guide Explains Making AI API Operations Idempotent at the Application Boundary

A production guide from the DEV Community frames idempotency for AI API operations as a reliability control contract rather than a one-off setting. It recommends binding a caller-supplied idempotency key to an authenticated principal, operation, and canonical request digest, then reserving the operation atomically and persisting its terminal result. The article argues that model call IDs are only correlation data and cannot replace such a ledger. It also separates client setup, gateway responsibilities, and provider protocols, and includes a review record and failure tests for evidence retention. The author discloses that they work on Modelflare, an OpenAI-compatible AI API gateway.

0
ProgrammingDEV Community ·

Linkit: a free desktop bookmark manager that summarizes and semantically searches saved links

The developer built Linkit, a free desktop bookmark manager, after struggling to re-find links they had saved. Unlike browser bookmarks that store only a URL, Linkit fetches and summarizes each link as it is saved, producing key takeaways. It supports any OpenAI-compatible API or local models via Ollama, and offers meaning-based search over an embedded library. Additional features include an interactive knowledge graph, AI-curated collections, duplicate and link-health detection, and periodic curation insights. Recent updates also add refined interface scaling, safer storage switching, rollback-capable import/export, and clearer sync error handling.

0
ProgrammingDEV Community ·

Chibisafe file exposure risks start at upload policy, not download links

Chibisafe is a self-hosted file-sharing service with user accounts, API keys, albums, public links, and an admin dashboard, so its exposure extends beyond a single upload page. The article argues that security reviews should examine who can upload, list, or delete files, and whether public links are the only access path. It recommends mapping all upload entry points, confirming which routes are public, and verifying that admin functions and API-key scopes are properly restricted. A ZoomEye query found 55 instances matching the exact title "Chibisafe" on 2026-11-01, though the author notes this only establishes observed titles, not whether those instances are secure. The piece also stresses testing public link generation and revocation, deletion and retention behavior, and whether removed files remain reachable through direct storage URLs.