python-telegram-bot / python-telegram-bot/ptbcontrib
[FEATURE] Support MySQL in PTB_sqlalchemy_persistence
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 118
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
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
- Altering the test for postgres-uri in line 71.
- Use sqlalchemy-scoped-session bound to a mysql-database.
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in persistence.py at __init_database and __load_database, then inspect the PostgreSQL URI test around line 71 and its MySQL-backed behavior. Reproduce the updater failure with a SQLAlchemy-scoped session and verify that loaded data works correctly for MySQL without regressing PostgreSQL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, postgresql, python, sqlalchemy
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100