Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated settings #72

Closed
wants to merge 2 commits into from
Closed

Updated settings #72

wants to merge 2 commits into from

Conversation

UmarGit
Copy link
Contributor

@UmarGit UmarGit commented Feb 12, 2021

Updated settings for debugging and more variables to overcome bugs

Updated settings for debugging and more variables to overcome bugs
@enoren5
Copy link
Owner

enoren5 commented Feb 13, 2021

Hi @UmarGit! Thank you for continuing to troubleshoot and debug environmental variables in settings.py. I tested your changes, merged them into my local master branch, and pushed to Heroku. I noticed that the OpterationalError is still present and not quite resolved just yet. I look forward to seeing more progress soon. :)

@enoren5
Copy link
Owner

enoren5 commented Feb 13, 2021

@UmarGit: When I Google: ‘heroku ssl django operationalerror pgbouncer’, it turns up a known issue described in an on the official Heroku GitHub repo titled: “django.db.utils.OperationalError: server does not support SSL, but SSL was required #118”.

That is our issue precisely. A number of other users chimed in with a solution that seems to resolve the issue for all of them. The solution is to add:

del DATABASES['default']['OPTIONS']['sslmode']

after:

django_heroku.settings(locals())

When I make that change, I didn't bother committing the change or pushing to Heroku because my local Django dev server exits with this traceback:

File "/home/<user>/dev/projects/python/2018-and-2020/tarot_juicer/tarot_juicer/settings.py", line 150, in <module>
    del DATABASES['default']['OPTIONS']['sslmode']
KeyError: 'OPTIONS'

So this is probably not the solution we need.

@UmarGit
Copy link
Contributor Author

UmarGit commented Feb 14, 2021

Hey @enoren5

Today, I was very curious and after brain-storming, I see you had advised me to delete the sslmode key from database dictionary, but as we are trying to do that, we fail, because the problem is in the library, Like as:

django_heroku.settings(locals()) 

We need to delete the sslmode key after that line, but why ?

Because it is altering our assigned DATABASE_URL or modifying it, but How can I prove it ?

I directly jumped into the django_heroku library and found there, when we call this as django_heroku.settings(locals()) it checks for a env variable named DATABASE_URL and alter the DATABASE_URL as dj_database_url.config(conn_max_age=MAX_CONN_AGE, ssl_require=True)

Which is in our case, causing our server to throw OperationalError at /
server does not support SSL, but SSL was required

So after further, reading the library, I found that we can disable this behaviour of django_heroku by providing a flag as:

#databases=False
django_heroku.settings(locals(), databases=False)

So after that this behavior will be disabled and we can have our DATABASE value un-modified.

For Reference of the library go to your local tarot_juicer repo then venv/lib/python3.8/site-packages/django_heroku/core.py
in that file, you will get more clear idea, of what I am trying to explain

That's all I had done
Best Regards
Umar Ahmed

@enoren5
Copy link
Owner

enoren5 commented Feb 14, 2021

At line 149 in settings.py I changed: django_heroku.settings(locals()) to django_heroku.settings(locals(), databases=False). You can see that here: https://github.com/enoren5/tarot_juicer/blob/master/tarot_juicer/settings.py

I committed the change, pushed to Heroku, and rebuilt the project using the build pack. The SSL error appears to be gone. Hooray! But now there is a missing table trace-back:

ProgrammingError at /
column accounts_authtoggle.enable_protection does not exist
LINE 1: SELECT "accounts_authtoggle"."id", "accounts_authtoggle"."en...

You can see it here: https://tarot-juicer-next-iter.herokuapp.com/

I've seen this error before. It usually indicates that the the db needs to be migrated/makemigrations. When I ran those commands, I got this:

(venv) $ heroku run python manage.py makemigrations
› Warning: heroku update available from 7.47.7 to 7.47.12.
Running python manage.py makemigrations on ⬢ tarot-juicer-next-iter... up, run.1528 (Hobby)
postgres://jckmeibmxypuvn:11033b956dd9cc6011e8efb7d23d56bb277bef7e9634a31ae0f0b304f34e9667@ec2-3-231-241-17.compute-1.amazonaws.com:5432/d9eds0cfpna1li
{'default': {'NAME': 'd9eds0cfpna1li', 'USER': 'jckmeibmxypuvn', 'PASSWORD': '11033b956dd9cc6011e8efb7d23d56bb277bef7e9634a31ae0f0b304f34e9667', 'HOST': 'ec2-3-231-241-17.compute-1.amazonaws.com', 'PORT': 5432, 'CONN_MAX_AGE': 600, 'ENGINE': 'django.db.backends.postgresql_psycopg2'}}
No changes detected

(venv) $ heroku run python manage.py migrate
› Warning: heroku update available from 7.47.7 to 7.47.12.
Running python manage.py migrate on ⬢ tarot-juicer-next-iter... up, run.2673 (Hobby)
postgres://jckmeibmxypuvn:11033b956dd9cc6011e8efb7d23d56bb277bef7e9634a31ae0f0b304f34e9667@ec2-3-231-241-17.compute-1.amazonaws.com:5432/d9eds0cfpna1li
{'default': {'NAME': 'd9eds0cfpna1li', 'USER': 'jckmeibmxypuvn', 'PASSWORD': '11033b956dd9cc6011e8efb7d23d56bb277bef7e9634a31ae0f0b304f34e9667', 'HOST': 'ec2-3-231-241-17.compute-1.amazonaws.com', 'PORT': 5432, 'CONN_MAX_AGE': 600, 'ENGINE': 'django.db.backends.postgresql_psycopg2'}}
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, essays, generators, landings, sessions
Running migrations:
No migrations to apply.

Notice that the DATABASES environment variable (dictionary) is being printed? It looks like Heroku is using the postgresdb successfully. Woohooo!

I'm just not sure what I am doing wrong to overcome the migrations/migrate error now. Just to double check your advice from prior contracts, I even ran: $ heroku run python manage.py makemigrations accounts (notice that I specifically indicated the accounts app) which still returned: No changes detected in app 'accounts'. Any ideas what to try next?

@enoren5
Copy link
Owner

enoren5 commented Feb 18, 2021

First revert the migration as the name of auto toggle is changed:

$ python manage.py migrate accounts zero

Second migrate it with new name:

$ python manage.py migrate accounts

Resolves #69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants