Skip to content

Commit 2a9b1a5

Browse files
committed
Fix obsolete usage of flask.json.JSONEncoder
Flask's JSONEncoder class was removed in version 3.0 since the Python Standard Library provides its own json library. Instead, update the code to use either that or Flask's default JSON provider. Flask apps don't have a `.json_encoder` property anymore, the property is `.json`.
1 parent c92b04d commit 2a9b1a5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lnt/server/ui/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ def __call__(self, environ, start_response):
4646
return self.app(environ, start_response)
4747

4848

49-
class LNTObjectJSONEncoder(flask.json.JSONEncoder):
49+
class LNTObjectJSONEncoder(flask.json.provider.DefaultJSONProvider):
5050
"""Take SQLAlchemy objects and jsonify them. If the object has an __json__
5151
method, use that instead."""
5252

5353
def __init__(self, *args, **kwargs):
54-
super(LNTObjectJSONEncoder, self).__init__(*args, **kwargs)
54+
super().__init__(*args, **kwargs)
5555

5656
def default(self, obj):
5757
if hasattr(obj, '__json__'):
@@ -74,7 +74,7 @@ def default(self, obj):
7474

7575
return fields
7676

77-
return flask.json.JSONEncoder.default(self, obj)
77+
return super().default(self, obj)
7878

7979

8080
class Request(flask.Request):
@@ -140,7 +140,7 @@ def create_with_instance(instance):
140140
# Construct the application.
141141
app = App(__name__)
142142

143-
app.json_encoder = LNTObjectJSONEncoder
143+
app.json = LNTObjectJSONEncoder(app)
144144
# Register additional filters.
145145
create_jinja_environment(app.jinja_env)
146146

lnt/server/ui/regression_views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import flask
21
import sqlalchemy
32
import json
3+
import flask
44
from flask import g
55
from flask import abort
66
from flask import render_template
@@ -265,7 +265,7 @@ def name(cls):
265265
return cls.__class__.__name__
266266

267267

268-
class LNTEncoder(flask.json.JSONEncoder):
268+
class LNTEncoder(json.JSONEncoder):
269269
"""Encode all the common LNT objects."""
270270
def default(self, obj):
271271
# Most of our objects have a __json__ defined.
@@ -276,7 +276,7 @@ def default(self, obj):
276276
return
277277
if name(obj) == "SampleField":
278278
return obj.name
279-
return flask.json.JSONEncoder.default(self, obj)
279+
return flask.json.provider.DefaultJSONProvider.default(obj)
280280

281281

282282
@v4_route("/regressions/<int:id>", methods=["GET", "POST"])

0 commit comments

Comments
 (0)