polyfactory icon indicating copy to clipboard operation
polyfactory copied to clipboard

feat(sqla_factory): refresh object in async_session after commit to db

Open wangxin688 opened this issue 1 year ago • 5 comments

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 refresh to create_async() and create_batch_async() and default value is False. it will depends user's input in creation object.

wangxin688 avatar May 09 '24 10:05 wangxin688

cc: @adhtruong

vkcku avatar May 09 '24 18:05 vkcku

I think this PR is ready for review now

wangxin688 avatar May 10 '24 13:05 wangxin688

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/541

github-actions[bot] avatar May 10 '24 13:05 github-actions[bot]

@all-contributors add @wangxin688 for code

adhtruong avatar May 10 '24 17:05 adhtruong

@adhtruong

I've put up a pull request to add @wangxin688! :tada:

allcontributors[bot] avatar May 10 '24 17:05 allcontributors[bot]