Not using foreign keys directly

When working with foreign keys, accessing the related field will result in a database read. That can be eliminated by using *_id, which is the foreign key value that Django has already cached on the object to make this scenario more efficient.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
tasks.py
1
+
def trigger_tasks(queryset):
2
+
    for item in queryset:
3
+
        run_async_task(item.page.id)
Suggested changes
-
        run_async_task(item.page.id)
+
        run_async_task(item.page_id)
Commit suggestion

When working with foreign keys, accessing the related field will result in a database read. That can be eliminated by using *_id, which is the foreign key value that Django has already cached on the object to make this scenario more efficient.

Read more
Update tasks.py
We're your Django code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code indirect-foreign-key in your pyproject.toml file.

Read more about configuring Code Review Doctor.