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.

Order in which hooks are executed

See original GitHub issue

Is it possible to control somehow the order in which hooks are executed?

My use case is something like this:

class Festival(LifecycleModelMixin, models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(unique=True, null=True, blank=True)

    @hook(BEFORE_CREATE)
    def set_slug(self):
        self.slug = generate_slug(self.name)

    @hook(BEFORE_CREATE)
    def do_something_with_slug(self):
        print(f"Here we want to use our slug, but it could be None: {self.slug}")

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
rsinger86commented, Apr 4, 2022

Another idea: we support a “priority” kwarg to the @hook like this:

class Festival(LifecycleModelMixin, models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(unique=True, null=True, blank=True)

    @hook(BEFORE_CREATE, priorty=1)
    def set_slug(self):
        self.slug = generate_slug(self.name)

    @hook(BEFORE_CREATE, priorty=2)
    def do_something_with_slug(self):
        print(f"Here we want to use our slug, but it could be None: {self.slug}")
1reaction
EnriqueSoriacommented, Apr 4, 2022

Another idea: we support a “priority” kwarg to the @hook like this:

class Festival(LifecycleModelMixin, models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(unique=True, null=True, blank=True)

    @hook(BEFORE_CREATE, priorty=1)
    def set_slug(self):
        self.slug = generate_slug(self.name)

    @hook(BEFORE_CREATE, priorty=2)
    def do_something_with_slug(self):
        print(f"Here we want to use our slug, but it could be None: {self.slug}")

That would do the trick, if you want I could try to implement it

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to define Execution Order of Hooks in Cucumber - Tools QA
Order hooks to run in a particular sequence is easy to do. As we already know the way to specify hooks in cucumber-like...
Read more >
Execution Order of Hooks Cucumber - ProgramsBuzz
Cucumber execute Hooks in certain order but there is a way to change the order of the execution according to the need of...
Read more >
The post-Hooks guide to React call order - LogRocket Blog
Start by learning the React call order post-Hooks. ... That is to say, in what order the code is being executed in your...
Read more >
Rules of Hooks - React
The answer is that React relies on the order in which Hooks are called. Our example works because the order of the Hook...
Read more >
What is the order for execution of useEffect hook in react?
import React ; from "react" ; import · BrowserRouter ; Switch · Route ; from "react-router-dom" ...
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