# Mohammad Abu Khashabeh - Pre-commit hooks that catch Django problems early

Source: https://djangotv.com/videos/django-day-copenhagen/2026/mohammad-abu-khashabeh-pre-commit-hooks-that-catch-django-problems-early-django-day-2026/
Date: 2026-10-13
Speakers: Speaker 1, Speaker 2, Speaker 3

## Transcript

**Speaker 1:** [00:00] As your body need to sleep and the mind is negotiating. So I'll be quick as much as I can. I would like to talk about the pre-comets. This is what the topic would discuss in the first place. We're gonna walk through everything related to the pre-commits, actions, hooks, best practices and common bitfalls, ending up with a quick demo

[00:46] Okay. To be begin with, this is a break brief, a quick brief about myself. I'm engineering lead and Django contributor I spent the last eight years working with Django and Python ecosystem I'm jumping into front end whenever needed. Working with DevOps, which is this is the part I would like to contribute. More I'm really enthusiastic about the DevOps and when the Dev and Ops is being met. Okay Many of us have introduced issues while working on the div

[01:33] For one of the features on Django. maybe with missing migrations, leftover PDBs or breakpoints for the newest version of Python. Also fail test. and much more things that actually failed on the local environment but somehow it got deployed for the pre-prod environment and caused some issues. Okay, this is what we're gonna talk. The pre-comets. I think the name is self-explanatory, right? Because it turns and runs before the comet exists.

[02:22] There is always when working with Django there would be a migration file generated Let's take this example in the first place. Migration file being generated and overlooked eventually when deploying the feature. This is one of the examples. and go on for all of things we have already mentioned. This is how we can actually get rid of and use pre-commits as our guardrails to move forward with the with the safe deployment I would say. It comes up with variety of hooks that actually checking the migrations

[03:08] Cross-check the debug statement to make sure there is no breakpoints that cause the whole process to freeze. We have Python check as well that you know make sure the readiness and you know the whole process is working as it should yeah and one of the things that I think the other talks have addressed which is the security the security keys or the security variables within the project this is what I wanna talk to later

[03:54] so you may hear it twice The local pre-commets protect who installed them, but the CI protects the whole repo. This is what we gonna take for later where things to point actually there is two main files. The first one is the pre-commits file, which is all the pre-commits about. It has all the configurations which called dot prefixed by dot pre-commit YAML file by the way which is in configurable So it's a YAML file and the second thing is

[04:40] pre-commits within the CI which what we will explain later a bit Where actually the pre-commits are running. Okay, there is something need to bear in mind that the pre-commits not seeing all of our disks. It's only look at the files that would be staged Because you know there is a bit confusing when working with a pre-commits that the pre-commits should come across all the files which is genuinely not right so it's have the visibility on

[05:25] the files that have been staged in the first place yeah this is one of the common bitfolds working with pre-commits which is you know the Django migrations, files, Python files being generated by Django itself. Need to make sure the pre-commits, whatever the type is, not to go through the migration because this is system systemically generated by Django so we need to exclude which pre-commits gave us the ability to do that but there is issue that

[06:10] Many Django developers came across exclude that at the top of the file but there is something need to take care of not to start you know the exclude with leading slash because this means the migration only exists in the root project so by doing so which what Pointed as does needs to be treated as like pointed to make sure that pre-comets excluding all the migrations folder whenever it exists okay I think the order of the pre-commits

[06:58] is actually the product it's not the test so pre -com it's actually would say do the first cleanliness across the project then it goes to the format you know it it's sequential so it goes through all the hooks being installed but this is the right direction that any pre -commits should come with ending up with any migrations that this is actually recommended to keep the system checks for example the Django migration at the end

[07:44] Okay, not every hook is the same or equal. It makes all sense actually pre-commits offers variety of hooks that serves our use cases starting with formatting checks Making sure there is no security keys is being compromised or hard-coded, check private keys and much more but try to recap the most ones in this slide okay This is one of the things that I think relatively connected to the other sessions, which

[08:32] this is I think one of the things that we should focus on, given the AI era we we're actually living in. making sure there is no security, there is no public keys, there is no PIM files are being committed for the repo which is this is how the pre-commits gonna help to overcome Okay, believe it or not, I quoted this from GitHub statistics. There was 39 million of security key being breached or compromised in the twenty

[09:21] twenty four twenty-four. So this is one of the things that let us mo f focus more maybe on the security and I would say the guardrails for the securities and checks that comes before even the commit exists Okay, this is also one of the common bitfalls try to addressing There is without which is one of the command on the pre-commits file that says without pass files to false. Actually

[10:06] without doing so this is will cause an issue or actually we wouldn't get the best of pre-commits because what actually does here is what actually the pre-commits will come up with checking only the file that has been changed not all the working tree so this is one of the things that I think we should yeah take into consideration while working with pre-comets Also, there is one thing that's obviously being missed in all the projects that I used to work on, which is pointing that

[10:52] The system checks is being triggered whenever the application has been ready. This is the you know the boiler plate for Django if we didn't do this most likely that the pre-comets or the chicks will pass silently without any issues Okay, how bad commits still passes? I think this is one of the Interesting things. The first thing that the pre-comm pre-commits is not being installed at all. The second one is There is a gate to overlook the pre-commits, which is no verify.

[11:38] I quoted this Jeff. I think this is the official meme for Windows antivirus checks. Okay, so the other thing is the debug statements This is what we were discussing. Anyone who's working on the Django project could easily just overlook all of these comets. With no verify. That's the point the that we said in the beginning of the session that the CI protects the repo actually and pre-commets protects who installed them. If you can

[12:23] check if anyone who overlook or passes the pre-commits locally The CI in GitHub Actions, which is the file pointed out, will take care of the rest. If you missed anything, all the pre-commits or the checks will be caught here in the GitHub Actions So that's why it's the CI is complementary to the pre-commits moving forward we are all I think this is related because the repo is not the server. All of us have heard that it worked

[13:10] to It get to work on my machine. That's why the repo is not actually the machine. That's why we need to maintain the pre-commits across the repo itself and the GitHub actions or the CICD in general Okay, this is the third time actually. There is some recommendation not to use pre-commits. Pointed over here actually when there is a database action or database request that needs to be done So it's actually recommended not to be

[13:57] involved within the pre-commits, either on CI, which is what obviously will cause the CI or the pre-commits to work successfully locally and failed on the cloud. There is also many things. When you have many hooks to run, I think this justifies how people could just simply overlook or trying to pass the pre-commits because you know when we working on the big chunks of changes and trying to commit them you will end up with many errors and validations that may come may come up along the way

[14:43] either failed test either you know formatting issues and formatting conflict and so on so forth. So this means we not to recommend to pass the pre-commits bus but also reducing the chunks or the size of changes that are being done. Okay, here is a quick demo. Okay, so this is the pre-commits file we pointed out actually we s we specify we where

[15:29] or when exactly we would like to run here in the pre-commits this is the execute that like i said we could address on any files we would like to Okay, zooming in. Thank you. Okay, here is the list of hooks that we could use. I tried to you know gather all that we could do. You know there is variety of hooks that we can use like trailing white spaces, check Jason, YAML, etc. This I

[16:15] I truly believe that the God process comes with good governance because when the pre-comits is being you know unified locally on the CI this means all the developers they are working on the same repo will same the will follow the same structure and you know the same rules and the same tests Okay, there is one of the coolest hooks is the Pi upgrade. If you are working on let's say Python 3. Or Python 2 for example, the pre-comets will automatically replace or change

[17:00] The code that have been written into the earliest version of Python We have iSort, we have Flick8. This is you know for formatting stuff in the first place. One question, who knows the default hook for the pre-commits. The default hook for the pre-commits The default is the formatter. This is what pre-commits come up with from the early beginning. This was you know add-ons along the way to adapt the needs across the projects.

[17:47] One of the greatest things that I would like to highlight each time actually the security again, which is bandit, one of the commonly used hooks or libraries that come across the files and identify any I would say hard-coded securities, any breached or compromised variables or known things for the projects. So it would be caught in the pre -commits at that time. And here for sure the Django system check. This is make sure the Django and its readiness to move forward with the deployment because

[18:32] if again any migration file any you know reference before assignments and dummy errors that happening on the dev environment will be caught sooner before the commits are being exists okay Here is quickest tip. This is how to get ready with the pre-commits. First thing you need to make sure you have installed the pre-commits. Because the commands should be exist locally. This is already done from my end, if you can

[19:18] see. I think I need to zoom again. Okay, after afterwards we need to make sure that the pre comets are actually being installed. Not the pre-commit command, but all the hooks within. It comes with variety of you know checks, versioning and rules. So whenever pre-commit is being installed, if the precommits dot precomits, which is the origin file for the pre-comits, will be created, if not exist. So if you can see here dot get hook

[20:04] if you can quick look at I think there is. Oh, T. Okay. This is actually what pre-commits will do in the background to make sure Git is being forced to look at the pre-commits before jumping into any action, which is the get push. Okay, there is a quick Think we could do is

[20:49] running pre-commits. This is assuming this is the first time we use the pre-commits locally So we are running pre-commits on against all files. This will come up with changes that nobody gonna review on GitHub. If you can see, this is my changes that came up with. If you can see there is detected private key which is hard coded in the code that's why this is was for a purpose Also there is a debug statement. Debug statement which is pointing to

[21:34] You know breakpoints for the earliest version of Python or PDB for whom used to do earlier. Okay, there is also you know This is actually how GitHub or the CICD is are the second layer of security for the commits that the developers may come up with. just to make sure actually just pointing that I made a quick repo just for the sake of you know

[22:20] the session that has all the files to run the pre-commits. Here is a quick actions how the pre-commits actually running and how github can refuse or allow these commits to be passed If I rerun all the jobs, you can see that pre-commits if I used to do non-verify locally, GitHub w will never let the C D to process with the rest of the deployment

[23:07] Yeah, this is the repo I was pointing out. Huh? Just thank you. I think this is dedicated if anyone make up may have any questions so we can address

**Speaker 2:** [23:33] Wonderful. How many here run pre

**Speaker 1:** [23:42] I think the most

**Speaker 2:** [23:43] hey yeah, questions. I was wondering when you do run it in CI I know that pre-commit has a has a local cache so it's fast. Locally it doesn't have to install everything. again and again. It was also fast in the example here. Does it also cache across

**Speaker 1:** [24:09] Actually it depends on the GitHub runners or the processes that you are run in the first place. I think there is also option to cache pre-comets on the CI just for the sake of speed, but It's limited to the I would say installing Python and the other dependencies. No not more.

**Speaker 2:** [24:34] You mentioned that pre-commit runs on the files that you have changed. That's the default behavior. And then I was wondering if you have check migrations because you've changed your models in some way. But actually you forgot to create the migration. Is that a thing it can detect so you can have a command also that kind of runs general

**Speaker 1:** [25:06] Actually there is two things that will code this overlocking. The first one is the Python check that will point out that there is a migration file not being created. I think will show up in the terminal. The second thing is using the hook make migrations that which is dedicated in the first place to check any migration are being overlooked

**Speaker 2:** [25:34] Question

**Speaker 3:** [25:35] Okay, so a bit in the previous talk we had some experience from Ruby on Rails. And I have I'm not personally familiar but I have seen on article title level that they have something like a local CI which is basically they run all the CI tests on the local machine with motivation that local machines oftentimes are much more powerful than the CI machines. And then they do the sign-off where the they it's not cryptographic signature but they kind of tell that GitHub that this has been passed. So what do you think about running test K test suite from the pre

[26:20] -commit.

**Speaker 1:** [26:21] Pre-comets. Actually it depends of how much the number of tests that are being you know run in the first place. For the test suites again this is means when involve ma many checks within the CI or the pre-commits, this will take much more time. So it depends how we gonna adapt this. This actually from practical experience with the developers, they will end up with no verify locally. So the same thing will goes for CI. So my answer would be this depends on the nature of the project and how many tests

[27:09] will be run or triggered on that change. I hope I took your accent

**Speaker 2:** [27:19] Is there a way if something is caught in CI to let's say I put push a secret to because I forgot to pre-commit install and then suddenly I got my SSH key on the git repository. Should it be doing more than just failing? Can it do more than that?

**Speaker 1:** [27:41] You mean alerting?

**Speaker 2:** [27:44] Yeah.

**Speaker 1:** [27:45] Actually I don't think so, to be honest, but when the CI itself is being, you know, cancelled or rejected or fail failed for some reason, this is you know a red flag because something goes wrong actually you will get you know notification from github you your action is being yeah failed So yes. I would like to point out for and highlighting the security topic because I'm pretty sure pre-comets alone won't solve the issue. You know that simply we c couldn't just put that the secrets within Python files, right? It could be in YAML

[28:30] or whatever it is. So this is take us to the point of you know security managers and yeah other topics not related. What I'm trying to say that pre-commit is something very healthy to move forward with but you know that this should come up with other complementaries. like I said maybe security checks on the CI security objects like kube city cube kube city config for the security credentials I think this is already was pointed out in the earlier session. Yeah.

**Speaker 2:** [29:15] It's an old tool pre-commit and there's some new ones around too. That have do you have experience in I think preck? Is that

**Speaker 1:** [29:27] preck?

**Speaker 2:** [29:28] Yeah We can we can talk about it after.

**Speaker 1:** [29:33] Okay, can take it.

**Speaker 2:** [29:35] Thank you so much for the talk, Mohammed.

**Speaker 1:** [29:38] Thank you.

**Speaker 2:** [29:39] It's exactly the time that we are going to have bit of cake and coffee and that's

**Speaker 1:** [29:50] interesting.

**Speaker 2:** [29:51] Yeah. It will be I s I assume since it's not up here that is a reason that it would probably be downstairs. Can we s can we send out a scout? Yeah. So yeah, there's a break now. And the next speaker is Lionel. And there's a small change in the program because of that talk that went out then you are on a little bit earlier so we're back here at four o'clock not sixteen forty five as it says in the program but sixteen oh where Lionel will present his talk and then we'll probably continue with lightning talks after that. Yeah. See you then
