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

SQLite Error: no such table. #21

Closed
ripinet5 opened this issue Sep 24, 2018 · 6 comments
Closed

SQLite Error: no such table. #21

ripinet5 opened this issue Sep 24, 2018 · 6 comments
Assignees
Labels
bug Something that doesn't work as expected.

Comments

@ripinet5
Copy link

Steps to reproduce:

  1. Download current build
  2. Unpack and install dependencies
  3. Start the bot

When issuing /start in Telegram the bot produces with the following error:

Exception in thread Worker 661051424:
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: users

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/ubuntu/greed-master/worker.py", line 64, in run
    self.user = self.session.query(db.User).filter(db.User.user_id == self.chat.id).one_or_none()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2924, in one_or_none
    ret = list(self)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2995, in __iter__
    return self._execute_and_instances(context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3018, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 948, in execute
    return meth(self, multiparams, params)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
    context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
    exc_info
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 265, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 248, in reraise
    raise value.with_traceback(tb)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.user_id AS users_user_id, users.first_name AS users_first_name, users.last_name AS users_last_name, users.username AS users_username, users.credit AS users_credit \nFROM users \nWHERE users.user_id = ?'] [parameters: (661051424,)] (Background on this error at: http://sqlalche.me/e/e3q8)

Tried running the database generation script and then running the bot, the error persists.

[ubuntu@apollo greed-master]$ python3.6 -OO database.py
[ubuntu@apollo greed-master]$ python3.6 -OO core.py
greed-bot is now starting!
Timed out while calling get_updates(), retrying in 1 secs...
Timed out while calling get_updates(), retrying in 1 secs...
Exception in thread Worker 661051424:
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: users

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/ubuntu/greed-master/worker.py", line 64, in run
    self.user = self.session.query(db.User).filter(db.User.user_id == self.chat.id).one_or_none()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2924, in one_or_none
    ret = list(self)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 2995, in __iter__
    return self._execute_and_instances(context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3018, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 948, in execute
    return meth(self, multiparams, params)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
    context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
    exc_info
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 265, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 248, in reraise
    raise value.with_traceback(tb)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.user_id AS users_user_id, users.first_name AS users_first_name, users.last_name AS users_last_name, users.username AS users_username, users.credit AS users_credit \nFROM users \nWHERE users.user_id = ?'] [parameters: (661051424,)] (Background on this error at: http://sqlalche.me/e/e3q8)

[ubuntu@apollo greed-master]$ python -V
Python 2.7.15rc1
[ubuntu@apollo greed-master]$ python3 -V
Python 3.6.6

@Steffo99 Steffo99 self-assigned this Sep 24, 2018
@Steffo99 Steffo99 added the bug Something that doesn't work as expected. label Sep 24, 2018
@Steffo99
Copy link
Owner

I can't reproduce the bug, can you send me the [Database] section of your config file?

@ripinet5
Copy link
Author

ripinet5 commented Sep 25, 2018

By default this is present in the config.ini, afaik this indicates an in-memory sqlite database.

[Database]
; The database engine you want to use.
; Refer to http://docs.sqlalchemy.org/en/latest/core/engines.html for the possible settings.
engine = sqlite://

Running the script without changing SQLite to a local file-based database results in the error. If I change my engine to what you used above, the bot works as expected.

[Database]
; The database engine you want to use.
; Refer to http://docs.sqlalchemy.org/en/latest/core/engines.html for the possible settings.
engine = sqlite:///local.sqlite

I don't know enough to diagnose why the in-memory database doesn't work, but changing it to file-based seems to work just fine. Perhaps what you posted should be the default?

@ripinet5
Copy link
Author

Either way this issue can be closed as it is not a bug.

@Steffo99
Copy link
Owner

I'll leave this open, I want to check why the in-memory database didn't work for you.

(Also, if I recall correctly, you need three slashes to set a local file-based db.)

@Steffo99 Steffo99 reopened this Sep 25, 2018
@ripinet5
Copy link
Author

You are correct, it does require sqlite:///local.sqlite (three slashes). I didn't copy my config after I made my changes. Edited my original post.

@Steffo99
Copy link
Owner

I just realized the problem was that in-memory databases persist only for the current run of the program, so database.py generated the database, but it didn't exist anymore when core.py tried to access it.

Maybe I should change the default, as it is unclear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that doesn't work as expected.
Projects
None yet
Development

No branches or pull requests

2 participants