Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: NestedAsyncIO contextmanager #872

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 7 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions pydantic_aioredis/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from typing import Tuple
from typing import Union

import nest_asyncio
from pydantic_aioredis.abstract import _AbstractModel
from pydantic_aioredis.utils import bytes_to_string
from pydantic_aioredis.utils import bytes_to_string, NestedAsyncIO


class Model(_AbstractModel):
Expand Down Expand Up @@ -69,8 +68,8 @@ def __save_from_sync(self):
# Use nest_asyncio so we can call the async save
except RuntimeError:
io_loop = asyncio.new_event_loop()
nest_asyncio.apply()
io_loop.run_until_complete(self.save())
with NestedAsyncIO():
io_loop.run_until_complete(self.save())

@asynccontextmanager
async def update(self):
Expand Down
Loading
Loading