Closed ddahan closed 6 years ago
Sadly running into the same issue here.
Also got ssl_require=False
..
Seems this is due to this method: https://github.com/heroku/django-heroku/blob/433ac4b0b82fa41ee88c2bb501874a49b3aff5fc/django_heroku/core.py#L24
We'll need to find a better way to remove all the tables from the public schema for test teardown
An alternative would be to more simply do
DROP TABLE (SELECT * FROM information_schema.tables WHERE table_schema = 'public') CASCADE;
Issue persists. Please re-open the ticket.
The teardown logic causes test failures even though all tests pass.
Ran 33 tests in 1.945s
OK
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: role "postgres" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/test.py", line 56, in handle
failures = test_runner.run_tests(test_labels)
File "/app/.heroku/python/lib/python3.6/site-packages/django/test/runner.py", line 607, in run_tests
self.teardown_databases(old_config)
File "/app/.heroku/python/lib/python3.6/site-packages/django_heroku/core.py", line 41, in teardown_databases
self._wipe_tables(connection)
File "/app/.heroku/python/lib/python3.6/site-packages/django_heroku/core.py", line 33, in _wipe_tables
"""
File "/app/.heroku/python/lib/python3.6/site-packages/raven/contrib/django/client.py", line 127, in execute
return real_execute(self, sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: role "postgres" does not exist
-----> test command `python manage.py test` failed with exit status 1
cc/ @sigmavirus24 .
Please note: I'm already paying $10 per-month-per-pipeline for this service and it does not work. I've followed the official docs and used some of the hacks on various gists .... no luck.
Meanwhile Gitlab and Circle CI are both free and work really well.
@iMerica are you using the project from source or installing from PyPI? I'm not certain this fix was ever released. Testing from source would be best right now as it may unblock you and you can help verify this fixes the issue.
I'm currently experiencing this issue – has anyone found a solution?
@bwilliams18 This seems to be fixed on master, following @sigmavirus24 example, but not released:
An alternative would be to more simply do
DROP TABLE (SELECT * FROM information_schema.tables WHERE table_schema = 'public') CASCADE;
Check PR #20
Pypi releases don't include that: https://pypi.org/project/django-heroku/#history
Why are the tables being dropped at all? In-dyno databases are ephemeral
Is this resolved? I'm using the latest version of the library, and I still get the same error.
@sigmavirus24 could you please cut a new release with this fix? It's a tease knowing this issue was fixed almost 9 months ago, but not having access to it through PyPI :-)
@bwilliams18 This seems to be fixed on master, following @sigmavirus24 example, but not released:
An alternative would be to more simply do
DROP TABLE (SELECT * FROM information_schema.tables WHERE table_schema = 'public') CASCADE;
Check PR #20
Pypi releases don't include that: https://pypi.org/project/django-heroku/#history
Even pulling from master with the change from PR #20 in it, it does not work on the Heroku CI:
OK (skipped=2)
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
psycopg2.errors.SyntaxError: syntax error at or near "("
LINE 2: DROP TABLE (
^
Any other suggestions?
For those looking for a workaround I did this:
1) Add to settings.py:
TEST_RUNNER = 'app.test_runner.NoDbTearDownTestRunner'
2) Create file app/test_runner.py with:
from django.test.runner import DiscoverRunner
import os
class NoDbTearDownTestRunner(DiscoverRunner):
def teardown_databases(self, old_config, **kwargs):
""" Override the database teardown defined in parent class if needed """
if not os.environ.get("APP_SKIP_DB_TEARDOWN"):
super().teardown_databases(old_config, **kwargs)
3) In Heroku CI config set APP_SKIP_DB_TEARDOWN = True
This will stop Heroku CI from doing a DB teardown at the end of the tests (which breaks despite PR #20 etc) but will leave everything else as before.
This issue should be reopened for a couple reasons:
require_ssl
configuration fixed by #43 (though I have been unable to get that PR to work fully) raises an error.My current workaround is to add this below my django-heroku config to use SQLite for my CI environment only:
# TODO: This is a hack while waiting for
# https://github.com/heroku/django-heroku/issues/17
# to be resolved.
if os.environ.get('CI'):
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'HerokuCI'
}
When running Heroku CI with in-dyno Postgres database, I got a
django.db.utils.ProgrammingError: role "postgres" does not exist
error.Here is my app.json
Here is the heroku test setup log (succeed)
Here is the heroku test log (fails)
Additional note
ssl_require=False
, otherwise it does not work at all.