Skip to content

Commit

Permalink
Replace JsonDict with a better-maintained implementation (hasgeek#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace authored Dec 22, 2022
1 parent 94e7137 commit 1103f20
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repos:
- toml==0.10.2
- tomli==2.0.1
- repo: https://github.com/PyCQA/isort
rev: v5.11.3
rev: 5.11.4
hooks:
- id: isort
additional_dependencies:
Expand Down
4 changes: 3 additions & 1 deletion funnel/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.dialects import postgresql
from sqlalchemy_json import mutable_json_type
from sqlalchemy_utils import LocaleType, TimezoneType, TSVectorType, UUIDType
import sqlalchemy as sa # noqa
import sqlalchemy.orm # Required to make sa.orm work # noqa
Expand All @@ -18,7 +19,6 @@
BaseScopedIdNameMixin,
BaseScopedNameMixin,
CoordinatesMixin,
JsonDict,
NoIdMixin,
RegistryMixin,
RoleMixin,
Expand Down Expand Up @@ -49,6 +49,8 @@ def declarative_mixin(cls: T) -> T:
return cls


json_type: postgresql.JSONB = mutable_json_type(dbtype=postgresql.JSONB, nested=True)

db = SQLAlchemy()
# This must be set _before_ any of the models are imported
TimestampMixin.__with_timezone__ = True
Expand Down
4 changes: 2 additions & 2 deletions funnel/models/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from werkzeug.datastructures import MultiDict

from . import JsonDict, NoIdMixin, UUIDType, db, sa
from . import NoIdMixin, UUIDType, db, json_type, sa

__all__ = ['Draft']

Expand All @@ -16,7 +16,7 @@ class Draft(NoIdMixin, db.Model): # type: ignore[name-defined]

table = sa.Column(sa.UnicodeText, primary_key=True)
table_row_id = sa.Column(UUIDType(binary=False), primary_key=True)
body = sa.Column(JsonDict, nullable=False, server_default='{}')
body = sa.Column(json_type, nullable=False, server_default='{}')
revision = sa.Column(UUIDType(binary=False))

@property
Expand Down
6 changes: 3 additions & 3 deletions funnel/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ..typing import OptionalMigratedTables
from . import (
BaseScopedNameMixin,
JsonDict,
Mapped,
MarkdownCompositeDocument,
TimestampMixin,
Expand All @@ -27,6 +26,7 @@
UrlType,
UuidMixin,
db,
json_type,
sa,
)
from .comment import SET_TYPE, Commentset
Expand Down Expand Up @@ -108,7 +108,7 @@ class Project(UuidMixin, BaseScopedNameMixin, db.Model): # type: ignore[name-de
read={'all'},
datasets={'primary', 'without_parent', 'related'},
)
parsed_location = sa.Column(JsonDict, nullable=False, server_default='{}')
parsed_location = sa.Column(json_type, nullable=False, server_default='{}')

website = with_roles(
sa.Column(UrlType, nullable=True),
Expand Down Expand Up @@ -193,7 +193,7 @@ class Project(UuidMixin, BaseScopedNameMixin, db.Model): # type: ignore[name-de
datasets={'primary', 'without_parent'},
)
boxoffice_data = with_roles(
sa.Column(JsonDict, nullable=False, server_default='{}'),
sa.Column(json_type, nullable=False, server_default='{}'),
# This is an attribute, but we deliberately use `call` instead of `read` to
# block this from dictionary enumeration. FIXME: Break up this dictionary into
# individual columns with `all` access for ticket embed id and `promoter`
Expand Down
3 changes: 3 additions & 0 deletions migrations/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# the 'revision' command, regardless of autogenerate
# revision_environment = false

compare_type = True
compare_server_default = True
render_as_batch = False

# Logging configuration
[loggers]
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ from_first = true
# add_imports = 'from __future__ import annotations'
known_future_library = ['__future__', 'six']
known_first_party = ['baseframe', 'coaster', 'funnel']
known_sqlalchemy = ['alembic', 'sqlalchemy', 'sqlalchemy_utils', 'flask_sqlalchemy', 'psycopg2']
known_sqlalchemy = ['alembic', 'sqlalchemy', 'sqlalchemy_utils', 'flask_sqlalchemy', 'psycopg2', 'sqlalchemy_json']
known_flask = [
'flask',
'click',
Expand Down Expand Up @@ -141,9 +141,9 @@ env_files = ['.env', '.env.testing']

[tool.pyright]
venv = 'hasgeek'

reportMissingImports = true
reportMissingTypeStubs = false
reportShadowedImports = false

pythonVersion = '3.7'

Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ requests
rich
rq
SQLAlchemy>=1.4.33
sqlalchemy-json
SQLAlchemy-Utils
tweepy
twilio
Expand Down
8 changes: 6 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async-timeout==4.0.2
# via
# aiohttp
# redis
attrs==22.1.0
attrs==22.2.0
# via aiohttp
babel==2.11.0
# via
Expand Down Expand Up @@ -286,7 +286,7 @@ paramiko==2.12.0
# via fabric3
passlib==1.7.4
# via -r requirements.in
phonenumbers==8.13.2
phonenumbers==8.13.3
# via -r requirements.in
premailer==3.10.0
# via -r requirements.in
Expand Down Expand Up @@ -431,15 +431,19 @@ six==1.16.0
# python-dateutil
# requests-file
# requests-mock
# sqlalchemy-json
# tuspy
sqlalchemy==1.4.45
# via
# -r requirements.in
# alembic
# coaster
# flask-sqlalchemy
# sqlalchemy-json
# sqlalchemy-utils
# wtforms-sqlalchemy
sqlalchemy-json==0.5.0
# via -r requirements.in
sqlalchemy-utils==0.38.3
# via
# -r requirements.in
Expand Down
6 changes: 3 additions & 3 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
astroid==2.12.13
# via pylint
attrs==22.1.0
attrs==22.2.0
# via
# cattrs
# flake8-bugbear
Expand Down Expand Up @@ -107,7 +107,7 @@ importlib-metadata==5.2.0
# flask
iniconfig==1.1.1
# via pytest
isort==5.11.3
isort==5.11.4
# via
# -r requirements_dev.in
# flake8-isort
Expand Down Expand Up @@ -259,7 +259,7 @@ types-python-dateutil==2.8.19.5
# via -r requirements_dev.in
types-pytz==2022.7.0.0
# via -r requirements_dev.in
types-requests==2.28.11.5
types-requests==2.28.11.6
# via -r requirements_dev.in
types-setuptools==65.6.0.2
# via -r requirements_dev.in
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async-generator==1.10
# via
# trio
# trio-websocket
attrs==22.1.0
attrs==22.2.0
# via
# outcome
# pytest
Expand Down

0 comments on commit 1103f20

Please sign in to comment.