Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Errors after test run #39

Open
brodul opened this issue Dec 18, 2018 · 4 comments
Open

Errors after test run #39

brodul opened this issue Dec 18, 2018 · 4 comments

Comments

@brodul
Copy link

brodul commented Dec 18, 2018

When I run ./manage.py test on GitLab CI I get the following error.

After test output:

Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 294, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "SCHEMA": syntax error

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 "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
    super().run_from_argv(argv)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/core/management/commands/test.py", line 56, in handle
    failures = test_runner.run_tests(test_labels)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/test/runner.py", line 607, in run_tests
    self.teardown_databases(old_config)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django_heroku/core.py", line 41, in teardown_databases
    self._wipe_tables(connection)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django_heroku/core.py", line 33, in _wipe_tables
    """
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "/root/.local/share/virtualenvs/project-xauW7Ao3/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 294, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "SCHEMA": syntax error

Work around is to call settings only on heroku:

if 'HEROKU' in os.environ:
    import django_heroku
    django_heroku.settings(locals())

Might be related to #31 but the traceback differs a lot.

@wwin3286tw
Copy link

wwin3286tw commented Feb 19, 2019

if 'HEROKU' in os.environ:
    import django_heroku
    django_heroku.settings(locals())

No longer work.
To find out why, run this command.

heroku run python3
python3
>>>import os
>>>os.environ

Will find out.

Now, I use this code

import os
if '/app' in os.environ['HOME']:
    import django_heroku
    django_heroku.settings(locals())

To avoid error.
If you have a better way, please let me know.

@bennett39
Copy link

Having the same problem on Travis CI.

Near identical traceback:

Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 296, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "SCHEMA": syntax error
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 "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
    super().run_from_argv(argv)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/core/management/commands/test.py", line 56, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/test/runner.py", line 607, in run_tests
    self.teardown_databases(old_config)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django_heroku/core.py", line 41, in teardown_databases
    self._wipe_tables(connection)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django_heroku/core.py", line 33, in _wipe_tables
    """
  File "/home/travis/virtualenv/python3.6.3/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 "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 296, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "SCHEMA": syntax error
The command "python manage.py test" exited with 1.

@wwin3286tw 's suggestion worked, and build now passes

@janhh
Copy link

janhh commented Mar 12, 2019

Same issue confirmed. I've approached this slightly different. I am new with Heroku so I might misunderstand something, but I think this is cleaner since it gives me more control over the environment variable I'll be looking for. Credit.

$ heroku config:set I_AM_HEROKU=yes -a APP
if 'I_AM_HEROKU' in os.environ:
    # Configure Django App for Heroku.
    import django_heroku
    django_heroku.settings(locals())

@Mustapha-Belkacim
Copy link

I had the same issue, but with Travis CI. The problem was that for some reason the commits to the default sqlite database didn't work, so setting a postgresql database solved it for me

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

No branches or pull requests

5 participants