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

JSONStorage ignore custom JSON libraries like ujson #712

Closed
Paolo97Gll opened this issue Sep 29, 2021 · 0 comments · Fixed by #713
Closed

JSONStorage ignore custom JSON libraries like ujson #712

Paolo97Gll opened this issue Sep 29, 2021 · 0 comments · Fixed by #713
Assignees
Labels
confirmed This issue is confirmed and requires action enhancement Make it better!

Comments

@Paolo97Gll
Copy link

Context

  • Operating System: Ubuntu 20.04.3 LTS
  • Python Version: Python 3.9.7
  • aiogram version: 2.15
  • aiohttp version: 3.7.4.post0
  • uvloop version (if installed): 0.16.0

Expected Behavior

When using JSONStorage, JSONStorage.read and JSONStorage.write should parse JSON with the custom compatible installed library. So, if I choose to install ujson, I expect that these two methods will use ujson.load and ujson.dump methods for JSON parsing.

Current Behavior

JSONStorage ignore custom JSON libraries and use the default json library, because the json library import is done by simply using:

import json

Possible solutions

I have found two possible solutions:

  • Change the import statement with something like:

    try:
        import ujson as json
    except ImportError:
        import json
  • Currently is not possible to change import json to from ...utils import json to automatically use the custom installed library (as done here or in lots of other files in the library), because aiogram/utils/json.py implements only dumps and loads methods. In order to use from ...utils import json, you would have to implement also dump and load methods.

@Olegt0rr Olegt0rr self-assigned this Sep 30, 2021
@Olegt0rr Olegt0rr added enhancement Make it better! confirmed This issue is confirmed and requires action labels Sep 30, 2021
Olegt0rr added a commit that referenced this issue Sep 30, 2021
@Olegt0rr Olegt0rr mentioned this issue Sep 30, 2021
9 tasks
JrooTJunior pushed a commit that referenced this issue Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue is confirmed and requires action enhancement Make it better!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants