Update dependencies and fix deprecations

This commit is contained in:
Lexi / Zoe 2022-09-17 16:42:38 +02:00
parent 0d4fbef13d
commit 19d264a03b
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
8 changed files with 154 additions and 131 deletions

View file

@ -6,11 +6,11 @@ from flask import Flask
from tofu_api.api import TofuApiBlueprint
from tofu_api.common.config import Config
from tofu_api.common.json import JSONEncoder
from tofu_api.common.json import JSONProvider
from tofu_api.dependencies import Dependencies
# Enable deprecation warnings in dev environment
if not sys.warnoptions and os.getenv('FLASK_ENV') == 'development':
if not sys.warnoptions and os.getenv('FLASK_DEBUG'):
warnings.filterwarnings('default', module='tofu_api.*')
@ -20,7 +20,7 @@ class App(Flask):
"""
# Override Flask classes
config_class = Config
json_encoder = JSONEncoder
json_provider_class = JSONProvider
# Set type hint for config
config: Config

View file

@ -1 +1 @@
from .json_encoder import JSONEncoder
from .json_provider import JSONProvider

View file

@ -1,16 +1,16 @@
from datetime import datetime
from typing import Any
from flask.json import JSONEncoder as _FlaskJSONEncoder
from flask.json.provider import DefaultJSONProvider
__all__ = [
'JSONEncoder',
'JSONProvider',
]
class JSONEncoder(_FlaskJSONEncoder):
class JSONProvider(DefaultJSONProvider):
"""
Custom JSON encoder built on top of the Flask JSONEncoder class.
Custom JSON provider.
"""
def default(self, obj: Any) -> Any:
@ -25,5 +25,5 @@ class JSONEncoder(_FlaskJSONEncoder):
if hasattr(obj, 'to_dict'):
return obj.to_dict()
# Fallback to the Flask JSONEncoder
# Fallback to the default JSON provider
return super().default(obj)

View file

@ -10,7 +10,7 @@ __all__ = [
]
@as_declarative(name='BaseModel', metadata=MetaData())
@as_declarative(metadata=MetaData())
class BaseModel:
"""
Declarative base class for database models.
@ -46,9 +46,9 @@ class BaseModel:
"""
Return the object's data as a dictionary.
By default, the dictionary will contain all table columns (with their column name as key) defined in the model. This can be
overridden by setting the `fields` and/or `exclude` parameters, in which case only fields that are listed in `fields` will be
included in the dictionary, except for fields listed in `exclude`.
By default, the dictionary will contain all table columns (with their column name as key) defined in the model.
This can be overridden by setting the `fields` and/or `exclude` parameters, in which case only fields that are
listed in `fields` will be included in the dictionary, except for fields listed in `exclude`.
"""
# Determine fields to include in dictionary (starting will all table columns)
included_fields = set(column.name for column in self.__table__.columns)