Repository navigation
refactor: Beanie documents are the entities, with no domain copies or hand-written conversions - #424
Merged
Merged
Conversation
…avedScriptChanges for updates
…s dataclass copies go
…ties, with typed changes for updates
…eclare indexes as Annotated so mypy sees their types; creates insert the caller's document
…admin updates; the unused User schema goes
…updates; SagaInstance goes
…ageChanges for status updates; RetryPolicy takes the retry count
…th ReplaySessionChanges for updates; the document embeds the domain ReplayConfig instead of a copy, and the uncalled get_replay_status goes
…UserSettingsChanges for updates; events apply field by field instead of through dict merges
…n values through TypeAdapter
…ead of splatting a dump into the constructor
…the same; a comment says why null keeps a value
…nd update changes, schemas stay in the routes
HardMax71
enabled auto-merge (squash)
October 20, 2026 18:43
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Closes #423, part of #308. Every stored entity lived three times, as a schema, a domain dataclass and a Beanie document, and routes and repositories copied between them with
**model_dump()andasdict(). mypy can't check those copies, so #308'sSecretStrchange would have meant three unchecked edits per field.Changes
The document is the entity now. Services and repositories take and return documents, the mirror dataclasses and their create and update variants are gone, and nothing under
services/ordb/imports a schema. An update's changes are aTypedDictthat the route builds with aTypeAdapter: a field left out keeps its value,nullclears a nullable one, andnullon a field that can't be empty now answers 422. Embedded values are domain dataclasses inbson_encoders, and indexed fields areAnnotated[..., Indexed()], so mypy sees their real types.Warning
Where this departs from #423:
init_beanieonce on a mocked database, so documents build through their constructors;model_construct()would skip validation.SystemSettingsstays. It's the value insideSystemSettingsDocument.config, not a copy of the document.nullas "unchanged", since the settings page sendsnullfor the sections it didn't touch.get_replay_statusandReplaySessionStatusInfoare deleted instead of converted.py.typed(BeanieODM/lazy_model#16).Type of Change
Test Plan
cd backend && uv run pytest tests/unit)cd frontend && npm run test)docker compose exec -T backend sh -c 'uv sync --group test --no-dev --frozen --no-install-project --no-build && pytest tests/e2e')cd frontend && npm run test:e2e)./deploy.sh openapi, then./deploy.sh types), never edited by handValidation: ruff,
mypy --strict, the orphan check, 573 unit tests, the Grafana contract tests andmkdocs build --strictpass../deploy.sh openapileaves the spec unchanged. The full backend e2e suite with k3s in a container and the worker gives 493 passed, 1 skipped here and 489 passed, 1 skipped on main in the same setup. The 4 extra are the new tests.Checklist
pre-commit run --all-filesand all checks passSummary by cubic
Makes Beanie documents the single entity for stored data. They previously lived three times — as an API schema, a domain dataclass, and a Beanie document — with routes and repositories copying between them via
**model_dump()andasdict(); those copies bypass mypy, so the plannedSecretStrchange would have meant three unchecked edits per field. Services and repositories now take and return documents, the mirror dataclasses and their create/update variants are gone, and nothing underservices/ordb/imports a schema.Behavior and adoption notes
TypedDicts validated byTypeAdapterin the routes: a missing key keeps the stored value,nullclears a nullable field, andnullon a field that can't be empty answers 422.nullas "unchanged", since the settings page sendsnullfor sections it didn't touch.SystemSettingsstays as the value insideSystemSettingsDocument.config, and the uncalledget_replay_statusandReplaySessionStatusInfoare deleted instead of converted.Annotated[..., Indexed()]so mypy sees the wrapped type; document constructor arguments aren't checked untillazy-modelshipspy.typed.init_beanieonce on a mocked database, so documents build through their validated constructors rather thanmodel_construct().Written for commit 02c38fe. Summary will update on new commits.