@e-dard Just wanted to get your thoughts on this.
The basic idea here is that if USE_S3 is unset, then in the case where app.debug is True (and USE_S3_DEBUG is False), we'd simply turn USE_S3 to False. This offers a couple advantages:
- No need to check
app.config on every call of url_for. We simply override it if USE_S3 is True at initialization. I don't think app.config could ever change without restarting the app (and even it it's possible, it's a serious anti-pattern, I think).
- The application can reference
app.config["USE_S3"] as a definitive test as to if files are being served locally or remotely. The use case I have for this is an app that allows users to upload images, which go directly to S3 (they never exist on the web server, except in memory between the upload and the upload to S3). I use the url_for function in S3 to generate those urls still, but then locally/testing I need to upload them to the filesystem. As of now, this requires:
if app.config['USE_S3'] and (not app.debug or app.config['USE_S3_DEBUG']):
s3_upload()
else: # not app.config['USE_S3'] or (app.debug and not app.config['USE_S3_DEBUG'])
local_upload()
which ideally would simplify to
if app.config['USE_S3']:
s3_upload()
else: # not app.config['USE_S3']
local_upload()