question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling database transactions

See original GitHub issue

I noticed that graphene-django doesn’t handle database transactions. I believe this is a issue that people should know or be careful about.

The same logic of DRF could be implemented as in the lines below that run in the dispatch method.

https://github.com/encode/django-rest-framework/blob/d985c7cbb999b2bc18a109249c583e91f4c27aec/rest_framework/views.py#L65-L102

Basically on one exception runs:

atomic_requests = settings.get('ATOMIC_REQUESTS', False)
if atomic_requests and connection.in_atomic_block:
   transaction.set_rollback(True)

In implementing this in graphene-django as we do not have the exception could run the rollback in the error checking of the execution result as in line 171.

https://github.com/graphql-python/graphene-django/blob/968002f1554e3a7a1c0617682be64b67823b2581/graphene_django/views.py#L167-L190

What do you think about this implementation?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ace-hancommented, Jan 31, 2020

Hello, any progress on this issue or PR?

1reaction
overidecommented, Feb 8, 2021

@jkimbo I tried wrapping mutate method in Django’s transaction.atomic decorator and it worked. Why can’t we use it ? Just curious

@classmethod
@transaction.atomic
def mutate(cls, root, info, **kwargs):
    # do something
Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Transactions - Documentation - Telerik
A transaction is an ordered sequence of operations that transforms a database from one state of consistency to another state of consistency. The...
Read more >
Understanding how database transactions are handled
Understanding how database transactions are handled. Introduction; Handling transactions explicitly with execute(); Warning – conn begin(), commit() and ...
Read more >
Handling Transactions - OutSystems 11 Documentation
Handling Transactions. While processing a web request, OutSystems begins a database transaction on its first access to the database.
Read more >
Transaction Management - GeeksforGeeks
A transaction usually means that the data in the database has changed. One of the major uses of DBMS is to protect the...
Read more >
SQL - Transactions - Tutorialspoint
Properties of Transactions · Atomicity − ensures that all operations within the work unit are completed successfully. · Consistency − ensures that the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found