Fix/global dataclass serailization#23
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a custom SQLAlchemy TypeDecorator to transparently serialize dataclass values stored in WeLearnDocument.details into JSON-compatible dictionaries, and updates unit tests to exercise this behavior.
Changes:
- Introduce
DetailsDictTypeDecorator to recursively serialize dataclass instances for JSON storage. - Update
WeLearnDocument.detailsto useDetailsDictso dataclass values can be persisted. - Update
tests/test_document_related.pyto use anAuthorDetailsdataclass indetails, and bump project version to1.5.1.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
welearn_database/data/models/document_related.py |
Switch details column to the new DetailsDict custom JSON type. |
welearn_database/data/details_dict.py |
Add custom TypeDecorator that serializes dataclasses before binding JSON parameters. |
tests/test_document_related.py |
Update tests to store a dataclass in details["author"], exercising the new serialization. |
pyproject.toml |
Bump package version to 1.5.1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
samonaisi
approved these changes
Jun 18, 2026
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.
This pull request introduces a new custom SQLAlchemy type to handle dataclasses in the
detailsfield of theWeLearnDocumentmodel and updates the test suite to use this new approach. The main change is the addition of theDetailsDicttype, which automatically serializes dataclass instances to dictionaries when saving to the database. This ensures better compatibility and flexibility for structured data in thedetailscolumn. The test cases are updated to use anAuthorDetailsdataclass for theauthorfield, reflecting the new serialization logic.Key changes are as follows:
Database Model and Serialization Improvements:
DetailsDictSQLAlchemyTypeDecoratorinwelearn_database/data/details_dict.pythat recursively converts dataclass instances (including nested and list/dict values) into dictionaries for storage in JSON columns.detailsfield in theWeLearnDocumentmodel (welearn_database/data/models/document_related.py) to use the newDetailsDicttype, ensuring automatic serialization of dataclasses. [1] [2]Testing Updates:
AuthorDetailsdataclass intests/test_document_related.pyand updated all test cases to use this dataclass for theauthorfield in thedetailsdictionary, ensuring tests align with the new serialization logic. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]Version Bump:
1.5.0to1.5.1inpyproject.tomlto reflect these changes.