Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebd808f326 |
@@ -8,18 +8,18 @@ helpers for the common paths, with a raw escape hatch for everything else.
|
||||
`requirements.txt`:
|
||||
|
||||
```
|
||||
mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.4
|
||||
mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.5
|
||||
```
|
||||
|
||||
Direct:
|
||||
|
||||
```bash
|
||||
pip install "mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.4"
|
||||
pip install "mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.5"
|
||||
```
|
||||
|
||||
Requires `motor` and `pymongo` (pulled transitively).
|
||||
|
||||
Drop the `@v0.1.4` suffix from the line above to install the latest unpinned.
|
||||
Drop the `@v0.1.5` suffix from the line above to install the latest unpinned.
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "mongo"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
description = "async mongodb wrapper over motor with a raw escape hatch"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
|
||||
+9
-1
@@ -67,7 +67,15 @@ class MongoDB:
|
||||
return self
|
||||
|
||||
async def __aenter__(self) -> "MongoDB":
|
||||
return await self.connect()
|
||||
try:
|
||||
return await self.connect()
|
||||
except BaseException:
|
||||
# connect()/ping failing here would otherwise leak the motor client (built
|
||||
# eagerly in __init__ with a background topology monitor + pool) — __aexit__
|
||||
# is not called when __aenter__ raises. close it before propagating so a
|
||||
# retry loop against a flapping server doesn't accumulate live clients.
|
||||
self.close()
|
||||
raise
|
||||
|
||||
async def __aexit__(self, exc_type, exc, tb) -> None:
|
||||
self.close()
|
||||
|
||||
Reference in New Issue
Block a user