quart-motor
quart-motor copied to clipboard
Quart 0.18 & JSONEncoders
I've removed json_encoders from Quart 0.18 and replaced it with a JSONProvider interface (Flask is doing the same). I'm told this breaks Quart-Motor. Please ask if you need help migrating and thanks for maintaining this extension.
Indeed, Quart-Motor uses following helper:
https://github.com/marirs/quart-motor/blob/d2d62916e4f35e66db97619af4e658268c9c3c15/quart_motor/helpers.py#L5
https://github.com/marirs/quart-motor/blob/d2d62916e4f35e66db97619af4e658268c9c3c15/quart_motor/helpers.py#L59-L96
Whereas Quart now uses:
https://github.com/pallets/quart/blob/547578f355b6b9438b08aefbbb65e6446c8290ef/src/quart/json/provider.py#L18-L35
class JSONProvider:
"""A standard set of JSON operations for an application. Subclasses
of this can be used to customize JSON behavior or use different
JSON libraries.
To implement a provider for a specific library, subclass this base
class and implement at least :meth:`dumps` and :meth:`loads`. All
other methods have default implementations.
To use a different provider, either subclass ``Quart`` and set
:attr:`~quart.Quart.json_provider_class` to a provider class, or set
:attr:`app.json <quart.Quart.json>` to an instance of the class.
:param app: An application instance. This will be stored as a
:class:`weakref.proxy` on the :attr:`_app` attribute.
"""
def __init__(self, app: Quart) -> None:
self._app = weakref.proxy(app)
Hoping maintainers can upgrade the code (many thanks to them).
Will have a look this weekend
FYI locally I have made the following changes that seem to work (haven't tested extensively):
# --- helpers.py ---
# class JSONEncoder(quart_json.JSONEncoder):
class JSONEncoder(quart_json.provider.DefaultJSONProvider):
...
def __init__(self, app, json_options, *args, **kwargs):
# ^^^ added "app"
# --- __init__.py ---
# Instead of:
self._json_encoder = partial(JSONEncoder, json_options=json_options)
# Replaced with:
self._json_provider_class = partial(JSONEncoder, json_options=json_options)
# Instead of:
app.json_encoder = self._json_encoder
# Replaced with:
app.json = self._json_provider_class(app=app)
Attempts to mimic https://github.com/pallets/quart/blob/547578f355b6b9438b08aefbbb65e6446c8290ef/src/quart/app.py#L291
Also, JSONEncoder
probably needs to be renamed JSONProvider
.
@marirs do you still plan on fixing this issue or is the project abandoned?
I would also love to have this fixed. Thank you for your work on this project!
Hi all, sorry for the long delay, I'll have this fixed by end of coming week for sure. was so busy in a lot of personal stuff.
Hi @JonathanBrenner @davideandres95 - can you test it. I've released the newer version and let me know.
Thanks to @clementwanjau for taking the time to update this.
@marirs The new changes do seem to work for me! I did run into another incompatibility issue with Pymongo 4.0 and opened a pull request to fix it. https://github.com/marirs/quart-motor/pull/6
@JonathanBrenner - Kindly check now, did the merge and update to pypi as well!
Thanks
Everything looks good on my end. Thanks @marirs !
Thanks a lot and sorry again for the delay :)
closing this issue finally ;)