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.

The post_process() method is skipped if `db_transaction = False`

See original GitHub issue

If you set db_transaction = False on your service and implement a post_process() method, the post process method does not execute. While examining the code, it makes sense why because the on transaction commit hook is being used. However, the behavior is a bit obtuse especially if you are not familiar with the internals of the library.

The solution I propose is if db_transaction = False and a post_process() is implemented, then automatically execute the post_process() in sequence after the process(). This would be useful for services where transaction safety is not needed (like an API call, etc.) and would make the feature in parity when db_transaction = True.

I do believe it’s as easy as implementing a finally statement:

    @contextmanager
    def _process_context(self):
        """
        Returns the context for :meth:`process`
        :return:
        """
        if self.db_transaction:
            with transaction.atomic(using=self.using):
                if self.has_on_commit_action:
                    transaction.on_commit(self.post_process)
                yield
        else:
            try:
                yield
            finally:
                if self.has_on_commit_action:
                    self.post_process()

Note: I would likely rename has_on_commit_action to has_post_process_action since it would not be transaction related.

Alternatively, we could throw an exception if you define a post_process when transaction is false however I think making the feature act in parity is better.

Please let me know your thoughts and I’d be happy to make a PR.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
c17rcommented, Dec 11, 2019

Merged in #52, thanks!

1reaction
c17rcommented, Dec 5, 2019

I don’t think post_process should run if the main part of the process fails. I see the intent of post_process being for things like notifications/syncing/etc which shouldn’t fire if things have failed and the database hasn’t updated.

But I do think post_process should run regardless of the transaction setting as long as an exception doesn’t make it all the way to the library level.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Transactions or SaveChanges(false) and ...
I have been investigating transactions and it appears that they take care of themselves in EF as long as I pass false to...
Read more >
D ADF Equivalents of Common Oracle Forms Triggers
Have it return true if the validation succeeds or false if the validation fails. Then, add a Method validator for this validation method...
Read more >
DbTransaction Class (System.Data.Common)
Gets a value that indicates whether this DbTransaction instance supports database savepoints. If false , the methods SaveAsync(String, CancellationToken), ...
Read more >
Zapatos: Zero-Abstraction Postgres for TypeScript - Jawj
If true , it enumerates its progress in generating the schema. It defaults to false . If you generate your schema programmatically, you...
Read more >
17.1.7.3 Skipping Transactions
If not, undo the transaction manually on the server where it originally took place. To skip the transaction, choose one of the following...
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