Christian, FYI you can do this already for all new connections with
something like this in an apps.py:

from django.db.backends.signals import connection_created

@connection_created.connect
def transactions_readonly(*, connection, **kwargs):
    with connection.cursor() as cursor:
        cursor.execute("SET SESSION TRANSACTION READ ONLY")

On Wed, 1 Jul 2020 at 21:38, Szeles Andor <andor.se...@gmail.com> wrote:

> Hello Simon and Christian,
>
> good point, making a particular connection read only would be even better
> than using a modified atomic.
>
> This way, if I really do need to use a read only transaction, I could just
> simply wrap my view inside an atomic decorator like
> @transaction.atomic(using='readonly')
>
> On the PostgreSQL side it would simple require adjusting
>> get_new_connection[2] to pass the option to psycopg2's set_session[3].
>>
>
> Yes, I believe that should work. We could also add the 'deferrable' flag
> this way easily.
>
> Many thanks,
> Andor
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CANqAxHa810Zo6-0ZocV5Qj7a7242LC3%3DrHncMcUMNhhPqVjh-A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CANqAxHa810Zo6-0ZocV5Qj7a7242LC3%3DrHncMcUMNhhPqVjh-A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM1gmT5N3m7Dxm9HkLgu9B_qSUPrxFH7Hnv-rXjKxGmRYQ%40mail.gmail.com.

Reply via email to