#31958: Django ORM sync_to_async error FATAL: remaining connection slots are
reserved for non-replication superuser connections
-------------------------------------+-------------------------------------
               Reporter:  super-sam  |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  ORM Async
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I am trying to implement Asynchronous
 support(https://docs.djangoproject.com/en/3.1/topics/async/) for Django
 ORM to write many records in Database(Postgres).

 I am getting the ERROR:root:**FATAL: remaining connection slots are
 reserved for non-replication superuser connections**

 ''I am creating coroutines add adding them to running the asyincio loop''
 {{{
 # Helper Class
 class ModelsHelper:
     @staticmethod
     @sync_to_async
     def __handle_resource_data(data):
           // Some calculation to create kwargs dict
           return Resource.objects.get_or_create(**kwargs)

     async def store_data(metric):
         // some calculation to get data
         return await ModelsHelper.__handle_resource_data(data)


 # Main File
 def get_event_loop():
         loop = None
         try:
             loop = asyncio.get_event_loop()
         except Exception as e:
             print(" New Event Loop ".center(50, '*'))
             loop = asyncio.new_event_loop()
             asyncio.set_event_loop(loop)
         return loop

 loop = get_event_loop()
 future = asyncio.ensure_future(
             asyncio.gather(*[ModelsHelper.store_data(metric) for metric in
 metrics]),
                 loop=loop
          )
 loop.run_until_complete(future)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31958>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.fc10aa4e486fb19289580b36288e86d3%40djangoproject.com.

Reply via email to