pytest-dev / pytest-dev/pytest-django
Request for documentation around best practice when running DB queries on Import
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I have an upstream which triggers the behaviour described in https://github.com/pytest-dev/pytest/issues/2825 and https://github.com/pytest-dev/pytest-django/issues/499 - they set a constant from a DB query which occurs during import.
I see some comments describing how to defer the query election (in https://stackoverflow.com/questions/43326132/how-to-avoid-import-time-database-access-in-django ) such as https://github.com/ionelmc/python-lazy-object-proxy, but is there a documented best practice on how to defer DB queries so they don't occur during import?
While reading pytest-django/issues/499 @pelme asserts that "Doing database queries at import time comes with a number of problems and should be avoided. Even if your code happens to work in your particular case, supporting this pattern in pytest-django is not feasible." but I can't find any supporting documentation for that assertion either.
Is there a page (or pages) which I can refer upstreams to which answer those questions?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing pytest issue #2825, pytest-django issue #499, and the linked Stack Overflow discussion to identify the documented risks and deferral practices. Then locate the project's documentation entry point and add guidance that answers how to avoid database queries during import and explains why the pattern is unsupported. Done means the guidance is clear enough to refer upstream users to.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- documentation, testing
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100