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

[FEATURE] Support MySQL in PTB_sqlalchemy_persistence #40

Open
kolja-wagner opened this issue Feb 26, 2022 · 2 comments
Open

[FEATURE] Support MySQL in PTB_sqlalchemy_persistence #40

kolja-wagner opened this issue Feb 26, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@kolja-wagner
Copy link

kolja-wagner commented Feb 26, 2022

PTB_sqlalchemy_persistence

Because other data in the project is already stored in mysql i've tried to adapt the code for using mysql instead of postgres. (And never run postgres myself, maybe this is already the source of the bug.)

Steps to reproduce

  1. Altering the test for postgres-uri in line 71.
  2. Use sqlalchemy-scoped-session bound to a mysql-database.
  3. start the updater

Actual behaviour

File "persistence.py", line 108, in __load_database:
self._chat_data = defaultdict(dict, self._key_mapper(data.get("chat_data", {}), int))
AttributeError: 'str' object has no attribute 'get'

For some reasons 'data' is of type 'str'. ("{}" after calling __init_database())

Solution

adding two lines of code at 105:

if isinstance(data, str):
    data = json.loads(data)

Version of Python, python-telegram-bot & dependencies:

$ python -m telegram
python-telegram-bot 13.11
Bot API 5.7
certifi 2021.10.08
Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]

mysql 8.0
sqlalchemy 1.4.27
conda 4.11.0
Windows 11

I thought somebody could find this interessting. Apart from this minor fix could this module named more general.

@kolja-wagner kolja-wagner added the bug 🐛 Something isn't working label Feb 26, 2022
@starry-shivam
Copy link
Member

Hi, first of all thanks for your feedback, tbh this is not really a "bug" since it doesn't mention anywhere that it works with MySQL too though having support for MySQL along with postgresql is really good idea! Would you like to create a PR with this change?

@starry-shivam starry-shivam added enhancement New feature or request and removed bug 🐛 Something isn't working labels Feb 27, 2022
@kolja-wagner
Copy link
Author

I might try, though i'am verry new to contributing to projects other than my own or from my commrades.

@Bibo-Joshi Bibo-Joshi changed the title [BUG]? Fix for using mysql [FEATURE] Support MySQL in PTB_sqlalchemy_persistence Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants