Skip to content

Commit c159a70

Browse files
committed
docs: align upsert_many scope notes with reverted single-row API
Post-revert (116b813), the docstring on ``OnConflictUpsert.supports_native_upsert`` was still the generic "Check if the dialect supports native upsert operations." Replace it with the precise scope: the flag is for the single-row ``create_upsert`` API on true ON-CONFLICT dialects; MERGE / INSERT OR UPDATE go through ``Repository.upsert_many`` and aren't reported here. Also extend ``docs/usage/repositories/basics.rst`` with a "Server-managed PK safety net" bullet documenting the resolver's transparent fallback when MERGE / INSERT OR UPDATE rows are missing PK columns — the same behavior the new ``BigIntPrimaryKey`` skip guards in the chunk-size tests exist to side-step.
1 parent 9e3e6ad commit c159a70

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

advanced_alchemy/operations.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,22 @@ class OnConflictUpsert:
409409

410410
@staticmethod
411411
def supports_native_upsert(dialect_name: str) -> bool:
412-
"""Check if the dialect supports native upsert operations.
412+
"""Check if the dialect supports the single-row ``create_upsert`` API.
413+
414+
This flag is scoped to the per-row ``INSERT ... ON CONFLICT`` /
415+
``ON DUPLICATE KEY UPDATE`` dialects that
416+
:meth:`OnConflictUpsert.create_upsert` can compile directly. The
417+
bulk ``MERGE`` (mssql, oracle) and ``INSERT OR UPDATE`` (spanner)
418+
primitives are dispatched separately by
419+
:meth:`Repository.upsert_many` via :func:`resolve_upsert_strategy`
420+
and are intentionally **not** reported here.
413421
414422
Args:
415423
dialect_name: Name of the database dialect
416424
417425
Returns:
418-
True if native upsert is supported, False otherwise
426+
``True`` for postgresql / cockroachdb / sqlite / mysql /
427+
mariadb / duckdb; ``False`` otherwise.
419428
"""
420429
return dialect_name in {"postgresql", "cockroachdb", "sqlite", "mysql", "mariadb", "duckdb"}
421430

docs/usage/repositories/basics.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ Important behaviors:
184184
- **``chunk_size``** mirrors ``add_many``: each chunk compiles to exactly one
185185
native statement (plus a re-SELECT for hydration on dialects without
186186
RETURNING).
187+
- **Server-managed PK safety net.** ``MERGE`` (oracle / mssql) and
188+
``INSERT OR UPDATE`` (spanner) cannot transparently invoke server-side
189+
``Sequence`` / ``Identity`` defaults the way ``INSERT ... ON CONFLICT``
190+
does on PostgreSQL. When any prepared row is missing a primary-key
191+
column on those dialects, ``upsert_many`` transparently falls back to
192+
the SELECT-then-partition path so the sequence/identity machinery
193+
runs normally. Models with Python-callable PK defaults (UUIDv6 /
194+
UUIDv7 / nano-id) keep the single-statement native path because
195+
the row is populated before dispatch.
187196
- **No breaking changes.** ``Sequence[ModelT]`` return shape is preserved;
188197
Litestar session / store callers using the single-row ``OnConflictUpsert``
189198
API are unaffected.

0 commit comments

Comments
 (0)