#17744 closed Bug (fixed)
override_settings has no effect on FileSystemStorage()
Reported by: | Michael van Tellingen | Owned by: | Claude Paroz |
---|---|---|---|
Component: | File uploads/storage | Version: | 1.4-beta-1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Since FileSystemStorage() copies the value of settings.MEDIA_ROOT to self.location on init. This means that changes to settings.MEDIA_ROOT have no effect.
I think the best solution here is to listen for the settings_changed signal and update the location value if the default value (which is settings.MEDIA_ROOT) is used. Unfortunately this cannot be solved when passing a custom location value based on the MEDIA_ROOT.
Otherwise this should be clearly documented.
I could create the patch if there is interest for this.
Attachments (1)
Change History (9)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
I hit the problem when using the following construct:
class TestCase(BaseTestCase): maxDiff = None def setUp(self): super(TestCase, self).setUp() # Create path to temp dir and recreate it temp_media_root = os.path.join( tempfile.gettempdir(), 'project-testrun') if os.path.exists(temp_media_root): shutil.rmtree(temp_media_root) os.mkdir(temp_media_root) self.override = override_settings(MEDIA_ROOT=temp_media_root) self.override.enable() def tearDown(self): shutil.rmtree(settings.MEDIA_ROOT) self.override.disable() super(TestCase, self).tearDown()
This makes sure I have a clean media_root for each test, which is a good thing. The documentation led me to believe this should be possible, but going through the source it was pretty easy to see that it is not.
Perhaps a clear warning in the documentation is enough, on the other hand I think something like this should work
comment:3 by , 13 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:4 by , 12 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
Reopening, as we didn't address this specific setting in #17787.
comment:5 by , 12 years ago
Owner: | changed from | to
---|---|
Severity: | Release blocker → Normal |
Status: | reopened → new |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Do you have need to change MEDIA_ROOT during of the life time of a FileSystemStorage instance and get it to react to such changes?.
Note: All this in the context of running tests because modification of settings isn't supoported in other scenarios.