jmcarp / jmcarp/nplusone

[django] Multi-table inheritance is broken when querying common list

Open
#36 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.1k
Forks
54
PR merge metrics
No merged PRs in 30d

Description

The use case is querying the **common** list using a base model when going to access submodel fields.
In this case you have to make `.select_related('submodel1_rel_field', 'submodel2_rel_field')` to avoid N+1 queries.
But if you have 0 records for any submodel you get exception
> Potential unnecessary eager load detected on `BaseModel.submodel_rel_field`

The current workaround is:
```python
NPLUSONE_WHITELIST = [
{'model': 'admin.*'},
{'label': 'unused_eager_load', 'model': 'app.BaseModel', 'field': 'submodel1_rel_field'},
{'label': 'unused_eager_load', 'model': 'app.BaseModel', 'field': 'submodel2_rel_field'},
]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.