Skip to content

docs(serializers): make the custom serializer examples cache (LAB-7491) - #458

Merged
27Bslash6 merged 3 commits into
mainfrom
lab-7491-custom-serializer-docs
Oct 2, 2026
Merged

27Bslash6 merged 3 commits into
mainfrom
lab-7491-custom-serializer-docs

Conversation

@27Bslash6

@27Bslash6 27Bslash6 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

The custom-serializer examples in docs/serializers/ now cache when used, and the Pydantic one is a doc test that fails if they stop.

pydantic.md "Advanced: Custom PydanticSerializer" built SerializationMetadata(format="MSGPACK", ...). The keyword is serialization_format and takes a SerializationFormat, so serialize() raised TypeError on every write. A decorated call logs that failure and returns the result uncached, and the fence never called the function, so the doc test passed.

  • pydantic.md: fixed the keyword and dropped the original_type branch that could never run (obj was already a dict by then). The fence now calls the function twice over a FileBackend in a temp directory and asserts the second call is a hit, and that a hit returns the dict, not the model.
  • custom.md "Example: Pydantic Serializer" was a verbatim copy of the same broken block. It now links to the pydantic.md example.
  • custom.md "Implementation Guide" passed format="custom" and size_bytes=, and neither keyword exists. A string format would still fail every write, because to_dict() reads .format.value. Its deserialize(self, data) had no metadata parameter, but the decorator passes metadata on every read, so a serializer built from the guide never got a hit. Both are fixed, and "Requirements" now states the signatures.
  • custom.md "See Also" said the API Reference covers "SerializationMetadata fields". It does not mention them, so the link now goes to its Serializers section, worded like the sibling pages.

The fence fails on the bug

With only the keyword reverted (serialization_format= back to format=):

$ uv run pytest --markdown-docs docs/serializers/pydantic.md -q
...
    assert get_user(1) == {"id": 1, "name": "Alice"}  # hit: the dict the serializer stored
AssertionError
------------------------------ Captured log call -------------------------------
ERROR    cachekit.cache_handler:provider.py:62 Serialization failed with <fence.PydanticSerializer object at 0x...>: TypeError
WARNING  cachekit.cache_handler:provider.py:58 Failed to store in backend cache for <redacted:41de4670287d0cf9>: SerializationError
ERROR    cachekit.cache_handler:provider.py:62 Serialization failed with <fence.PydanticSerializer object at 0x...>: TypeError
WARNING  cachekit.cache_handler:provider.py:58 Failed to store in backend cache for <redacted:41de4670287d0cf9>: SerializationError
=========================== short test summary info ============================
FAILED docs/serializers/pydantic.md::[CodeFence#3][line:103] - Error in code ...
========================= 1 failed, 5 passed in 0.13s ==========================

With the fix the same command gives 6 passed.

Implementation Guide, run through @cache

The guide's class, with custom_encode and custom_decode set to msgpack, decorated over a FileBackend and called twice:

Serializer Body runs Second call
Guide as fixed 1 hit
serialization_format="custom" (a string) 2 miss; ERROR "Serialization failed … AttributeError" and a WARNING on each write
Old deserialize(self, data) 2 miss; ERROR "Deserialization failed … TypeError" on each read

Checks

  • uv run pytest --markdown-docs README.md docs/: 132 passed
  • uv run pytest tests/docs/: 70 passed
  • grep -rn -A4 'SerializationMetadata(' README.md docs/ | grep -E '\bformat=|size_bytes=': no output

The PydanticSerializer example built SerializationMetadata(format=...),
which raises TypeError, so every write failed. The decorator logs the
failure and returns the result uncached, and the fence never called the
function, so the doc test passed anyway.

- pydantic.md: use serialization_format=SerializationFormat.MSGPACK, drop
  the original_type branch that could never run, and call the function
  twice over a FileBackend, asserting the second call is a hit.
- custom.md: point "Example: Pydantic Serializer" at that example instead
  of keeping a second broken copy. Fix the Implementation Guide to pass
  only real SerializationMetadata parameters and to accept the metadata
  argument the decorator passes to deserialize; state both in Requirements.
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: cachekit-io/cachekit-py/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 69375368-d64d-4ddf-9871-41dd344cfeff

📥 Commits

Reviewing files that changed from the base of the PR and between 0b71441 and 5541b1c.

📒 Files selected for processing (2)
  • docs/serializers/custom.md
  • docs/serializers/pydantic.md
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kodus-27b

kodus-27b Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

…vers (LAB-7491)

The API Reference documents serializer parameters, not SerializationMetadata fields; link its Serializers section with the wording the sibling pages use.
@kodus-27b

kodus-27b Bot commented Oct 2, 2026

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@27Bslash6
27Bslash6 merged commit e2e0b7f into main Oct 2, 2026
36 checks passed
@27Bslash6
27Bslash6 deleted the lab-7491-custom-serializer-docs branch October 2, 2026 19:59
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