PaulSonOfLars / tgbot

Modular telegram group management bot
GNU General Public License v3.0
723 stars 920 forks source link

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres #109

Closed nlienard closed 2 years ago

nlienard commented 2 years ago

HI

I installed postgres and all dependencies but get an error with "postgres" for SQLALCHEMY_DATABASE_URI.

root@rpi4-cloud:~/telegram/tgbot# python3 -m tg_bot
2022-02-19 19:38:00,629 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2022-02-19 19:38:00,629 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/telegram/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/root/telegram/tgbot/tg_bot/modules/admin.py", line 12, in <module>
    from tg_bot.modules.disable import DisableAbleCommandHandler
  File "/root/telegram/tgbot/tg_bot/modules/disable.py", line 19, in <module>
    from tg_bot.modules.sql import disable_sql as sql
  File "/root/telegram/tgbot/tg_bot/modules/sql/__init__.py", line 16, in <module>
    SESSION = start()
  File "/root/telegram/tgbot/tg_bot/modules/sql/__init__.py", line 9, in start
    engine = create_engine(DB_URI, client_encoding="utf8")
  File "<string>", line 2, in create_engine
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/create.py", line 534, in create_engine
    entrypoint = u._get_entrypoint()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/url.py", line 661, in _get_entrypoint
    cls = registry.load(name)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/langhelpers.py", line 344, in load
    "Can't load plugin: %s:%s" % (self.group, name)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
root@rpi4-cloud:~/telegram/tgbot#

if i replaced by "postgresql", i got another error:

root@rpi4-cloud:~/telegram/tgbot# python3 -m tg_bot
2022-02-19 19:39:32,557 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2022-02-19 19:39:32,558 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1803, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.NumericValueOutOfRange: integer out of range

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

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/telegram/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/root/telegram/tgbot/tg_bot/modules/admin.py", line 14, in <module>
    from tg_bot.modules.helper_funcs.extraction import extract_user
  File "/root/telegram/tgbot/tg_bot/modules/helper_funcs/extraction.py", line 7, in <module>
    from tg_bot.modules.users import get_user_id
  File "/root/telegram/tgbot/tg_bot/modules/users.py", line 11, in <module>
    import tg_bot.modules.sql.users_sql as sql
  File "/root/telegram/tgbot/tg_bot/modules/sql/users_sql.py", line 172, in <module>
    ensure_bot_in_db()
  File "/root/telegram/tgbot/tg_bot/modules/sql/users_sql.py", line 71, in ensure_bot_in_db
    SESSION.commit()
  File "<string>", line 2, in commit
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 1431, in commit
    self._transaction.commit(_to_root=self.future)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 829, in commit
    self._prepare_impl()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
    self.session.flush()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 3363, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 3503, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/langhelpers.py", line 72, in __exit__
    with_traceback=exc_tb,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 3463, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 633, in execute
    uow,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/persistence.py", line 249, in save_obj
    insert,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/persistence.py", line 1097, in _emit_insert_statements
    statement, multiparams, execution_options=execution_options
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1614, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/sql/elements.py", line 326, in _execute_on_connection
    self, multiparams, params, execution_options
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1491, in _execute_clauseelement
    cache_hit=cache_hit,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
    e, statement, parameters, cursor, context
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 2027, in _handle_dbapi_exception
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1803, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.DataError: (psycopg2.errors.NumericValueOutOfRange) integer out of range

[SQL: INSERT INTO users (user_id, username) VALUES (%(user_id)s, %(username)s)]
[parameters: {'user_id': xxxxxxx, 'username': 'xxxxxxxx'}]
(Background on this error at: https://sqlalche.me/e/14/9h9h)

Any clue is welcome.

Thanks

nlienard commented 2 years ago

i'll reply to myself

SOLUTION :

telegram_bot=# ALTER TABLE users ALTER COLUMN user_id TYPE bigint;
ALTER TABLE

The int is not enough. integer 4 bytes -2147483648 to +2147483647

My telegram id is over 5 000 000 000 which is largely superior than the the integer limit ( 214748364)

PaulSonOfLars commented 2 years ago

Hi, thanks for raising this issue.

The repo is no longer maintained. 64bit userids are just one of the many things which are likely to be broken in this bot.

I do not recommend using it :)

nlienard commented 2 years ago

thanks, closing the issue as it is solved.