heroku / django-heroku

[DEPRECATED] Do not use! See https://github.com/heroku/django-heroku/issues/56
BSD 3-Clause "New" or "Revised" License
459 stars 142 forks source link

Permit disabling 'require_ssl' when running locally for development #10

Open burcaw opened 6 years ago

burcaw commented 6 years ago

When using this module, I would like the ability to set ssl_require to False for the database connection in a scenario where the Postgres instance defined in DATABASE_URL is NOT hosted at Heroku.

Let me explain: During local development, I use a Postgres database on Localhost rather than my production Heroku Postgres instance. Requiring SSL complicates the local dev environment.

I'm not asking for any change to behavior when connecting to Heroku-hosted Postgres.

rhymes commented 6 years ago

It also overrides anything you pass in the connection string, so if you put "sslmode=disable" or "sslmode=allow" in the connection string, it doesn't work.

I ended up with something like this:

import django_heroku
import dj_database_url
django_heroku.settings(locals())
# override DATABASE_URL set by django_heroku because it forces SSL mode locally
ssl_require = os.environ['ENV'] != 'development'
locals()['DATABASES']['default'] = dj_database_url.config(
    conn_max_age=django_heroku.MAX_CONN_AGE, ssl_require=ssl_require)
ybakos commented 6 years ago

As an overworked developer, Given I am running in my development environment and I declare DATABASES = { 'default': dj_database_url.config(ssl_require=False) } When I use django_heroku.settings(locals()) Then the ssl_require=False option I specified should be honored.

Instead, I get the error:

psycopg2.OperationalError: server does not support SSL, but SSL was required

ddahan commented 6 years ago

I ended up with a very similar solution than @rhymes. However I think we all agree here to say it's a workaround and should be allowed directly in the django heroku parameters.

I really like the original purpose of this django-heroku package, as it creates an abstraction that says: "Hey, let me handle EVERY CONFIG related to Heroku". However, if in the end, we end up with a part of these settings in settings.py, and another part in django-heroku, it becomes harder to maintain. The point is, we should have either all config in settings.py (and not use django-heroku), either everything in django-heroku. A mix of them is the worst solution IMHO.

Can @kennethreitz (sorry man, I know how busy and stressed you currently are) tell us the way to go with this?

eltonplima commented 5 years ago

I found a different solution:

django_heroku.settings(locals(), logging=not DEBUG, databases=not DEBUG)

If you do not put logging, your logging configurations will not be respected.