odmantic icon indicating copy to clipboard operation
odmantic copied to clipboard

✨ Add new SyncEngine, support async and sync code - with fixed session

Open tiangolo opened this issue 3 years ago • 2 comments

✨ Add new SyncEngine, support async and sync code - with fixed session

This is the same as https://github.com/art049/odmantic/pull/225, but it includes the fixes to share the same session in https://github.com/art049/odmantic/pull/227

This would supersede https://github.com/art049/odmantic/pull/225 if the session fix in https://github.com/art049/odmantic/pull/227 is accepted.

I'm doing it here as an additional PR because there are a couple of changes and fixes needed in the new SyncEngine to handle that same issue with the session.

tiangolo avatar Jun 24 '22 23:06 tiangolo

Codecov Report

Merging #231 (8850bae) into master (623fa27) will decrease coverage by 0.05%. The diff coverage is 99.79%.

:exclamation: Current head 8850bae differs from pull request most recent head 51d2585. Consider uploading reports for the commit 51d2585 to get more accurate results

@@             Coverage Diff             @@
##            master     #231      +/-   ##
===========================================
- Coverage   100.00%   99.94%   -0.06%     
===========================================
  Files           38       38              
  Lines         2725     3424     +699     
  Branches       413      483      +70     
===========================================
+ Hits          2725     3422     +697     
- Misses           0        1       +1     
- Partials         0        1       +1     
Flag Coverage Δ
tests-3.6-4-standalone 98.29% <95.12%> (-1.42%) :arrow_down:
tests-3.6-4.2-standalone 98.29% <95.12%> (-1.42%) :arrow_down:
tests-3.6-4.4-standalone 98.29% <95.12%> (-1.42%) :arrow_down:
tests-3.7-4-standalone 98.14% <95.12%> (-1.38%) :arrow_down:
tests-3.7-4.2-standalone 98.14% <95.12%> (-1.38%) :arrow_down:
tests-3.7-4.4-standalone 98.14% <95.12%> (-1.38%) :arrow_down:
tests-3.8-4-replicaSet 98.30% <99.79%> (+0.36%) :arrow_up:
tests-3.8-4-standalone 98.10% <95.14%> (-1.35%) :arrow_down:
tests-3.8-4.2-sharded 96.90% <95.14%> (-1.05%) :arrow_down:
tests-3.8-4.2-standalone 98.10% <95.14%> (-1.35%) :arrow_down:
tests-3.8-4.4-standalone 98.10% <95.14%> (-1.35%) :arrow_down:
tests-3.9-4-standalone 97.98% <94.93%> (-1.32%) :arrow_down:
tests-3.9-4.2-standalone 97.98% <94.93%> (-1.32%) :arrow_down:
tests-3.9-4.4-standalone 97.98% <94.93%> (-1.32%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
odmantic/engine.py 99.20% <98.57%> (-0.80%) :arrow_down:
odmantic/__init__.py 100.00% <100.00%> (ø)
tests/integration/fastapi/test_doc_example.py 100.00% <100.00%> (ø)
tests/integration/test_embedded_model.py 100.00% <100.00%> (ø)
tests/integration/test_engine.py 100.00% <100.00%> (ø)
tests/integration/test_engine_reference.py 100.00% <100.00%> (ø)
tests/integration/test_query.py 100.00% <100.00%> (ø)
tests/integration/test_types.py 100.00% <100.00%> (ø)
tests/integration/test_zoo.py 100.00% <100.00%> (ø)

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

codecov[bot] avatar Jul 05 '22 18:07 codecov[bot]

I added a couple of small tests to check the errors when motor is not installed, this should fix the line missing coverage. :sunglasses:

tiangolo avatar Jul 13 '22 12:07 tiangolo

Awesome @tiangolo ! I just reviewed everything and it looks perfect to me.

There is just a tiny rebase required and it will be good for a merge! I can handle the documentation part if you want, it shouldn't be that long.

Can't wait to see what you plan to do with bulk_writes and switch_collection!

art049 avatar Aug 19 '22 13:08 art049

Actually I though about it again and it might be quite painful for existing users to have to change the dependency in order to upgrade to the new release. I think it would be smoother to let the motor dependency as required. I'm not totally sure but wdyt @tiangolo ?

art049 avatar Aug 21 '22 14:08 art049

Merged in #242 ! Many thanks @tiangolo ! 🔥

art049 avatar Aug 24 '22 20:08 art049

Awesome, thanks a lot! 🚀

About having Motor as optional or not, I think that's totally up to you. I get it that as ODMantic was always Motor-specific it could feel weird suddenly having that as optional.

If it was a new project, I guess it would be a no-brainer but I get that it can make sense to keep it required for backwards compatibility.

Maybe it can be done in a future release after having some warning in the docs for a while or something like that. Anyway, I don't feel strongly about it in one way or the other. 😅

tiangolo avatar Aug 24 '22 20:08 tiangolo