Skip to content

docs(readme): async + Pydantic v2 quickstart, override LIST and POST examples#7

Merged
svalench merged 1 commit into
masterfrom
docs/async-pydantic2-readme
Apr 25, 2026
Merged

docs(readme): async + Pydantic v2 quickstart, override LIST and POST examples#7
svalench merged 1 commit into
masterfrom
docs/async-pydantic2-readme

Conversation

@svalench
Copy link
Copy Markdown
Owner

Summary

Adds two new sections to the README that target the most common questions after the 1.2.x release:

  1. Async quickstart (SQLAlchemy 2.x + Pydantic v2) \u2014 a runnable AsyncBaseViewset example using the lazy db_conf helpers (Base, async_engine, get_async_session) and a Pydantic v2 schema with ConfigDict(from_attributes=True). Tables are created on FastAPI startup via async_engine.begin() / run_sync(Base.metadata.create_all).
  2. Overriding list and create_element \u2014 shows how to subclass AsyncBaseViewset to implement custom LIST (case-insensitive search + whitelist order_by) and custom POST (input normalization, mapping IntegrityError to HTTP 409).

Highlights

  • Documents the Pydantic v2 idiom users should follow (model_config = ConfigDict(from_attributes=True), model_dump(exclude_unset=True)).
  • Documents the register() contract: keep method names and the item body parameter, register() rewrites item annotation to response_model, so reusing one schema for request + response is the safe default.
  • Notes the 1.2.1 graceful fallback when the async DB-API driver (aiosqlite / asyncpg / aiomysql) is not installed.
  • No code changes \u2014 documentation only.

Verification

  • Manual review of the snippets against AsyncBaseViewset source and _RegisterMixin.register.
  • Examples follow the patterns already exercised in tests/test_viewsets_with_adapters.py::TestAsyncBaseViewsetWithAdapter.

- Add 'Async quickstart (SQLAlchemy 2.x + Pydantic v2)' section with
  AsyncBaseViewset, ConfigDict(from_attributes=True) schema, and
  startup-driven Base.metadata.create_all on async_engine.
- Add 'Overriding list and create_element' section showing how to
  subclass AsyncBaseViewset to implement case-insensitive search +
  whitelist ordering on LIST and input normalization + IntegrityError
  -> 409 on POST.
- Note caveats: register() patches item annotation to response_model;
  signatures and the 'item' body parameter must be preserved; keep
  one schema for request and response (or pre-validate inside the
  handler).
- Mention graceful sync fallback when async DB-API driver is missing
  (in line with 1.2.1 fix).
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@svalench svalench merged commit 368aa7d into master Apr 25, 2026
6 checks passed
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.

1 participant