File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ Don't forget to remove deprecated code on each major release!
3232
3333- Refactoring of internal code to improve maintainability. No changes to publicly documented API.
3434
35+ ### Fixed
36+
37+ - Fixed bug where prerendered components could generate a ` SynchronousOnlyOperation ` exception if they utilize the Django ORM.
38+
3539## [ 5.1.1] - 2024-12-02
3640
3741### Fixed
Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5+ import asyncio
56import contextlib
67import inspect
78import logging
1617from uuid import UUID , uuid4
1718
1819import dill
19- from asgiref .sync import async_to_sync
2020from channels .db import database_sync_to_async
2121from django .contrib .staticfiles .finders import find
2222from django .core .cache import caches
@@ -353,14 +353,18 @@ class SyncLayout(Layout):
353353 """
354354
355355 def __enter__ (self ):
356- async_to_sync (self .__aenter__ )()
357- return self
356+ self .loop = asyncio .new_event_loop ()
357+ self .thread = ThreadPoolExecutor (max_workers = 1 )
358+ return self .thread .submit (self .loop .run_until_complete , self .__aenter__ ()).result ()
358359
359- def __exit__ (self , * _ ):
360- async_to_sync (self .__aexit__ )(* _ )
360+ def __exit__ (self , * exec ):
361+ result = self .thread .submit (self .loop .run_until_complete , self .__aexit__ (* exec )).result ()
362+ self .loop .close ()
363+ self .thread .shutdown ()
364+ return result
361365
362366 def sync_render (self ):
363- return async_to_sync ( super (). render ) ()
367+ return self . thread . submit ( self . loop . run_until_complete , self . render ()). result ()
364368
365369
366370def get_pk (model ):
You can’t perform that action at this time.
0 commit comments