#17928: Tests with import time dependency on DB fail
-----------------------------------+--------------------------------------
Reporter: boxm | Owner: nobody
Type: Uncategorized | Status: reopened
Component: Testing framework | Version: SVN
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by boxm):
* status: closed => reopened
* resolution: needsinfo =>
Comment:
Replying to [comment:1 carljm]:
> Do you have a legitimate use case for an import-time database query? In
non-test code, those are almost always bugs, as they result in data that
never gets updated until a process restart; so it's a good thing if they
fail under test.
I believe I do have a valid use case. The code under test uses it to read
the domain name info from the Sites table (DOMAIN_NAME =
Site.objects.get_current().domain). I know that the domain is fixed, and
since my site is scaling to 10K+ requests/s I can't afford a DB query on
that path.
Thus the underlying use case is "read something from the database that you
know doesn't change often, where you can't afford the DB lookup in line".
The alternatives would be to cache this (hassle, more code), or to
initialise the variable later (all sorts of interesting race conditions).
While it might be true that doing this is sometimes a cause of bugs, those
should be caught by the user's test code explicitly checking it can change
the values and have things work, not by a blanket ban.
--
Ticket URL: <https://code.djangoproject.com/ticket/17928#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.