polyfactory
polyfactory copied to clipboard
feat(sqla_factory): refresh object in async_session after commit to db
Description
Use Case: column use server_default to generate default value in database side.
If we use asyncsession, and access this attribute from orm object, it will raise sqlalchemy.exc.MissingGreenlet error.
There are two ways to solve this issue.
- the first one, refresh it directly after commit (choice this one in this PR, which may add very little latency)
- the second one, add params
refreshtocreate_async()andcreate_batch_async()and default value is False. it will depends user's input in creation object.
cc: @adhtruong
I think this PR is ready for review now
Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/541
@all-contributors add @wangxin688 for code