tortoise-orm
tortoise-orm copied to clipboard
Feature: async default value
allow Field's default value not only be callable, literal value, but also async function
Description
when set Field's default keyword option to async function, then while save and create model, if the field never set, the field will be set as the async function's result
Motivation and Context
I write a model and I want a serial of unique, auto increasing serial names generate from redis (by aioredis), but the field's default do not support retrieve value from async function, I have to override create method, that's cumbersome.
and tortoise is an async orm, it should support async first.
How Has This Been Tested?
I create a new model for new test case, test model's behavior when combine async default with save
, create
, and when default field value was covered by set attribute.
I run tests on linux, include sqlite's test cases.
Almost no effect.
Checklist:
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added the changelog accordingly.
- [x] I have read the CONTRIBUTING document.
- [x] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
Thanks! LGTM. Please update changelog also.
Pull Request Test Coverage Report for Build 8858936385
Details
- 17 of 17 (100.0%) changed or added relevant lines in 1 file are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+0.02%) to 87.923%
Totals | |
---|---|
Change from base Build 8858003658: | 0.02% |
Covered Lines: | 5758 |
Relevant Lines: | 6453 |
💛 - Coveralls
I've done the change log, do you think we should update the doc? Seems that this behavior is natural, and there is no need to @long2ice
@YAGregor hi!
Please rebase PR on actual develop and resolve conflict in Changelog Changes should go to 0.21.0 section