Skip to content

Fix/global dataclass serailization#23

Merged
lpi-tn merged 3 commits into
mainfrom
Fix/global-dataclass-serailization
Jun 18, 2026
Merged

Fix/global dataclass serailization#23
lpi-tn merged 3 commits into
mainfrom
Fix/global-dataclass-serailization

Conversation

@lpi-tn

@lpi-tn lpi-tn commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces a new custom SQLAlchemy type to handle dataclasses in the details field of the WeLearnDocument model and updates the test suite to use this new approach. The main change is the addition of the DetailsDict type, which automatically serializes dataclass instances to dictionaries when saving to the database. This ensures better compatibility and flexibility for structured data in the details column. The test cases are updated to use an AuthorDetails dataclass for the author field, reflecting the new serialization logic.

Key changes are as follows:

Database Model and Serialization Improvements:

  • Added a new DetailsDict SQLAlchemy TypeDecorator in welearn_database/data/details_dict.py that recursively converts dataclass instances (including nested and list/dict values) into dictionaries for storage in JSON columns.
  • Updated the details field in the WeLearnDocument model (welearn_database/data/models/document_related.py) to use the new DetailsDict type, ensuring automatic serialization of dataclasses. [1] [2]

Testing Updates:

Version Bump:

  • Bumped the package version from 1.5.0 to 1.5.1 in pyproject.toml to reflect these changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DetailsDict TypeDecorator to recursively serialize dataclass instances for JSON storage.
  • Update WeLearnDocument.details to use DetailsDict so dataclass values can be persisted.
  • Update tests/test_document_related.py to use an AuthorDetails dataclass in details, and bump project version to 1.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.

Comment thread welearn_database/data/details_dict.py
Comment thread welearn_database/data/details_dict.py
Comment thread welearn_database/data/details_dict.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpi-tn lpi-tn merged commit 298e9fb into main Jun 18, 2026
4 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.

3 participants