Skip to content

Fix Flask 3 boot crash by porting the JSON encoder to the provider API - #29

Open
Bungeetaco wants to merge 1 commit into
8bitDream:masterfrom
Bungeetaco:flask3-port
Open

Fix Flask 3 boot crash by porting the JSON encoder to the provider API#29
Bungeetaco wants to merge 1 commit into
8bitDream:masterfrom
Bungeetaco:flask3-port

Conversation

@Bungeetaco

Copy link
Copy Markdown

When #6 bumped Flask to 3.1.3 the app stopped booting, and #22 pinned things back to Flask 2.2.5 + Werkzeug 2.3.8 to get workers up again. The actual root cause is that flask.json.JSONEncoder and app.json_encoder were removed in newer Flask, so importing AmiiboJSONEncoder crashes every gunicorn worker on boot.

This ports the encoder to the JSON provider API instead:

  • AmiiboJSONEncoder now subclasses flask.json.provider.DefaultJSONProvider, with the same default() logic and unchanged output
  • registered with app.json = AmiiboJSONEncoder(app) instead of app.json_encoder

The provider API has been around since Flask 2.2, so nothing changes on the currently pinned 2.2.5. It just makes a Flask 3 upgrade possible again whenever you want it. That also matters for newer Python, since Flask 2.2.5 does not run on 3.14 at all (pkgutil.get_loader is gone).

I have been running this self-hosted on Flask 3.1 / Python 3.14 with gunicorn and the full database serves fine, including the custom encoded fields (hex IDs, release dates, collections).

flask.json.JSONEncoder was removed in Flask 3; rebase AmiiboJSONEncoder
on flask.json.provider.DefaultJSONProvider and register it via app.json.
Needed to run on Python 3.14 where Flask 2.x no longer works.
@AbandonedCart

Copy link
Copy Markdown
Member

If we ever need to reinstall the server again, ill circle back to this. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants