MongoEngine / flask-mongoengine

MongoEngine flask extension with WTF model forms support
Other
840 stars 256 forks source link

Incompatibility with current flask version (2.2) #498

Closed prihoda closed 2 years ago

prihoda commented 2 years ago

Initializing MongoEngine now raises an exception, because app.json_encoder is now None:

>>> mongodb = MongoEngine(app)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/miniforge/lib/python3.8/site-packages/flask_mongoengine/__init__.py", line 102, in __init__
    self.init_app(app, config)
  File "/opt/miniforge/lib/python3.8/site-packages/flask_mongoengine/__init__.py", line 113, in init_app
    override_json_encoder(app)
  File "/opt/miniforge/lib/python3.8/site-packages/flask_mongoengine/json.py", line 38, in override_json_encoder
    app.json_encoder = _make_encoder(app.json_encoder)
  File "/opt/miniforge/lib/python3.8/site-packages/flask_mongoengine/json.py", line 8, in _make_encoder
    class MongoEngineJSONEncoder(superclass):
TypeError: NoneType takes no arguments

Please see flask changelog:

https://flask.palletsprojects.com/en/2.2.0/changes/#version-2-2-0

prihoda commented 2 years ago

@insspb tagging you for visibility, thanks!

davidism commented 2 years ago

I'll make this a deprecation warning in Flask for now, but note that app.json_encoder etc. are deprecated and will be removed in Flask 2.3. There is a new "JSON Provider" interface that allows complete customization of the JSON implementation.

It looks like you are ignoring deprecation warnings during tests. This is really unsafe, as you will not be notified early of changes to libraries you depend on. Tests should treat deprecation warnings as errors, so that you can either create compatibility code or explicitly acknowledge that you're ignoring a specific warning.

insspb commented 2 years ago

Hi @prihoda , @davidism

Next week or two I am on my main job, so here will be some delays with Flask-Mongoengine 2.0.0 work. Can you clarify is it report related to current pip version or to current master? (Flask-Mongoengine 2.0.0 preparation)

insspb commented 2 years ago

Ok, now everything is clear for me.

Fixed in #505 :

insspb commented 2 years ago

With #505 and #507 completely supported, and raising on deprecation warnings in future.

ErikBrendel commented 1 year ago

Do you have any idea when this change will be available via pip? Can you maybe backport this to flask-mongoengine 1 while version 2 is still in development? This would be super helpful for our Poject

VedantPatil1 commented 1 year ago

I was wondering the same thing. In the mean time can you please explain how to resolve the warning? I am having the same problem. Also I am not as experienced with flask or mongo. I am using Docker and docker compose with a requirements.txt file to install the dependencies and run the app, so any post installation steps are not viable to me. I you could keep that in mind that would be really helpful.