feat: add Attribute base class for custom model casts and sqlite cast tests - #57
Merged
Conversation
… tests - Add `Attribute(BaseModel)` to caster.py as a reusable mixin for custom ORM casts — subclasses get JSON serialize/deserialize for free via `get`/`set` classmethods backed by Pydantic's model_dump_json - Export `Attribute` from `fastapi_startkit.masoniteorm` - Fix `get_attributes_for_insert` to apply `set` casts to `_attributes` so `Address` instances and dicts can be passed directly to `create()` without manual JSON serialization - Add `preferences` (dict/list) and `address` (Attribute) columns to the users fixture table; seed and model updated accordingly - Add `test_sqlite_model_casts.py` covering int, str, bool, dict, list, and custom Pydantic Attribute casts including insert with instance/dict Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Attribute(BaseModel)tocaster.py— a reusable mixin that turns any Pydantic model into a custom ORM cast. Subclasses get JSON serialization/deserialization for free viaget/setclassmethods backed bymodel_dump_jsonAttributefromfastapi_startkit.masoniteormso users can import it directlyget_attributes_for_insertto applysetcasts to_attributes, allowingAddressinstances and dicts to be passed directly tocreate()without manual JSON serializationpreferences(dict/list) andaddress(Attributesubclass) columns to the users fixture table with seeder and model updatestest_sqlite_model_casts.pywith 11 tests coveringint,str,bool,dict,list, and custom PydanticAttributecasts — including insert with an instance and a dictUsage
Test plan
test_sqlite_model_casts.pypass🤖 Generated with Claude Code