Opened 4 years ago
Closed 4 years ago
#32242 closed Cleanup/optimization (wontfix)
@override_settings does not work with DATABASES
Reported by: | Peter Inglesby | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 3.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
#19031 introduced a warning that @override_settings
"may not work with DATABASES".
In the last seven years, things have changed so that @override_settings
does not work with DATABASES at all.
This is because once django.setup()
has been called, django.db.connections.databases
is cached via cached_property
, and so overriding the settings has no effect.
As such, the warning should be changed to an exception.
(I fully accept that anybody messing around with DATABASES
like this deserves all the trouble they encounter!)
Change History (2)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Component: | Uncategorized → Testing framework |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
IMO the current wording is clear enough "Overriding setting DATABASES can lead to unexpected behavior." and we shouldn't raise an exception. If someone really want to use override_settings
with DATABASES
and will mix it with deleting connections, mocking, et cetera.... I don't see a strong reason to prevent users from experimenting. Someone somewhere in the universe is probably using it with success 🖖.
If anybody stumbles across this via Google, this seems to work as a way of changing
DATABASES
:(In my case I wanted to switch a SQLite database to an in-memory SQLite database, but the principle should be the same.)
Tested with Django 3.1.4.