Skip to content

Conversation

@cofin
Copy link
Member

@cofin cofin commented Dec 10, 2025

Summary

Fixes two related edge-case handling issues where SQLSpec raised errors instead of handling gracefully.

The Problem

  1. SearchFilter raises TypeError when no search parameter is provided #281: SearchFilter raised TypeError when value=None was passed (common when no search query param provided)
  2. SQLBuilderError when calling set() with empty dict/kwargs #279: Update.set(**{}) raised SQLBuilderError (common with Pydantic/msgspec exclude_unset=True patterns)

The Solution

Handle edge cases at the source rather than requiring defensive checks everywhere:

  1. SearchFilter: Accept value: str | None - the append_to_statement method already handles None as no-op
  2. Update.set(): Return self unchanged when called with empty args/kwargs

Key Changes

  • sqlspec/core/filters.py: SearchFilter.__init__ accepts value: str | None
  • sqlspec/builder/_dml.py: set() returns early when not args and not kwargs
  • sqlspec/extensions/litestar/providers.py: Removed now-unnecessary # type: ignore comment

Closes #281, closes #279

- SearchFilter now accepts `value: str | None` to handle cases where
  no search parameter is provided (fixes #281)
- Update.set() now returns self unchanged when called with empty
  args/kwargs, supporting Pydantic/msgspec exclude_unset patterns (fixes #279)

Both fixes follow the principle of handling edge cases gracefully at
the source rather than requiring defensive checks everywhere.
@cofin cofin merged commit 92ebb0e into main Dec 10, 2025
10 checks passed
@cofin cofin deleted the feat/search-filter-none-handling branch December 10, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SearchFilter raises TypeError when no search parameter is provided SQLBuilderError when calling set() with empty dict/kwargs

2 participants