From 3b84e49fb771db7227cca32ee4e3fb5e583a4ed4 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Mon, 15 Sep 2025 13:11:49 -0700 Subject: [PATCH] Change Marshmallow "missing" to "load_default" on fields https://marshmallow.readthedocs.io/en/latest/upgrading.html#upgrading-to-3-13 --- tildes/tildes/schemas/comment.py | 2 +- tildes/tildes/schemas/listing.py | 18 +++++++++--------- tildes/tildes/views/api/web/comment.py | 2 +- tildes/tildes/views/api/web/group.py | 2 +- tildes/tildes/views/api/web/topic.py | 3 ++- tildes/tildes/views/api/web/user.py | 2 +- tildes/tildes/views/bookmarks.py | 2 +- tildes/tildes/views/login.py | 7 ++++--- tildes/tildes/views/message.py | 2 +- tildes/tildes/views/register.py | 2 +- tildes/tildes/views/topic.py | 8 ++++---- tildes/tildes/views/user.py | 8 ++++---- tildes/tildes/views/votes.py | 2 +- 13 files changed, 31 insertions(+), 29 deletions(-) diff --git a/tildes/tildes/schemas/comment.py b/tildes/tildes/schemas/comment.py index 01cfdd0..307d897 100644 --- a/tildes/tildes/schemas/comment.py +++ b/tildes/tildes/schemas/comment.py @@ -21,4 +21,4 @@ class CommentLabelSchema(Schema): """Marshmallow schema for comment labels.""" name = Enum(CommentLabelOption) - reason = SimpleString(max_length=1000, missing=None) + reason = SimpleString(max_length=1000, load_default=None) diff --git a/tildes/tildes/schemas/listing.py b/tildes/tildes/schemas/listing.py index 4cdc783..18e831a 100644 --- a/tildes/tildes/schemas/listing.py +++ b/tildes/tildes/schemas/listing.py @@ -16,9 +16,9 @@ from tildes.schemas.fields import Enum, ID36, Ltree, PostType, ShortTimePeriod class PaginatedListingSchema(Schema): """Marshmallow schema to validate arguments for a paginated listing page.""" - after = ID36(missing=None) - before = ID36(missing=None) - per_page = Integer(validate=Range(min=1, max=100), missing=50) + after = ID36(load_default=None) + before = ID36(load_default=None) + per_page = Integer(validate=Range(min=1, max=100), load_default=50) @validates_schema def either_after_or_before(self, data: dict, many: bool, partial: Any) -> None: @@ -32,11 +32,11 @@ class TopicListingSchema(PaginatedListingSchema): """Marshmallow schema to validate arguments for a topic listing page.""" period = ShortTimePeriod(allow_none=True) - order = Enum(TopicSortOption, missing=None) - tag = Ltree(missing=None) - unfiltered = Boolean(missing=False) - all_subgroups = Boolean(missing=False) - rank_start = Integer(data_key="n", validate=Range(min=1), missing=None) + order = Enum(TopicSortOption, load_default=None) + tag = Ltree(load_default=None) + unfiltered = Boolean(load_default=False) + all_subgroups = Boolean(load_default=False) + rank_start = Integer(data_key="n", validate=Range(min=1), load_default=None) @pre_load def reset_rank_start_on_first_page( @@ -62,7 +62,7 @@ class MixedListingSchema(PaginatedListingSchema): of just one or the other. """ - anchor_type = PostType(missing=None) + anchor_type = PostType(load_default=None) @pre_load def set_anchor_type_from_before_or_after( diff --git a/tildes/tildes/views/api/web/comment.py b/tildes/tildes/views/api/web/comment.py index f5b1e74..63e2f17 100644 --- a/tildes/tildes/views/api/web/comment.py +++ b/tildes/tildes/views/api/web/comment.py @@ -335,7 +335,7 @@ def delete_label_comment(request: Request, name: CommentLabelOption) -> Response @ic_view_config( route_name="comment_mark_read", request_method="PUT", permission="mark_read" ) -@use_kwargs({"mark_all_previous": Boolean(missing=False)}, location="query") +@use_kwargs({"mark_all_previous": Boolean(load_default=False)}, location="query") def put_mark_comments_read(request: Request, mark_all_previous: bool) -> Response: """Mark comment(s) read, clearing notifications. diff --git a/tildes/tildes/views/api/web/group.py b/tildes/tildes/views/api/web/group.py index ccb90ab..b717f5d 100644 --- a/tildes/tildes/views/api/web/group.py +++ b/tildes/tildes/views/api/web/group.py @@ -86,7 +86,7 @@ def delete_subscribe_group(request: Request) -> dict: @use_kwargs( { "order": Enum(TopicSortOption), - "period": ShortTimePeriod(allow_none=True, missing=None), + "period": ShortTimePeriod(allow_none=True, load_default=None), }, location="form", ) diff --git a/tildes/tildes/views/api/web/topic.py b/tildes/tildes/views/api/web/topic.py index 2d28557..40cb98f 100644 --- a/tildes/tildes/views/api/web/topic.py +++ b/tildes/tildes/views/api/web/topic.py @@ -158,7 +158,8 @@ def get_topic_tags(request: Request) -> dict: permission="tag", ) @use_kwargs( - {"tags": String(missing=""), "conflict_check": String(missing="")}, location="form" + {"tags": String(load_default=""), "conflict_check": String(load_default="")}, + location="form", ) def put_tag_topic(request: Request, tags: str, conflict_check: str) -> dict: """Apply tags to a topic with Intercooler.""" diff --git a/tildes/tildes/views/api/web/user.py b/tildes/tildes/views/api/web/user.py index a9b70f3..3ff8d87 100644 --- a/tildes/tildes/views/api/web/user.py +++ b/tildes/tildes/views/api/web/user.py @@ -357,7 +357,7 @@ def get_invite_code(request: Request) -> dict: @use_kwargs( { "order": Enum(TopicSortOption), - "period": ShortTimePeriod(allow_none=True, missing=None), + "period": ShortTimePeriod(allow_none=True, load_default=None), }, location="form", ) diff --git a/tildes/tildes/views/bookmarks.py b/tildes/tildes/views/bookmarks.py index 4c68b01..3b046d6 100644 --- a/tildes/tildes/views/bookmarks.py +++ b/tildes/tildes/views/bookmarks.py @@ -15,7 +15,7 @@ from tildes.views.decorators import use_kwargs @view_config(route_name="bookmarks", renderer="bookmarks.jinja2") @use_kwargs(PaginatedListingSchema()) -@use_kwargs({"post_type": PostType(data_key="type", missing="topic")}) +@use_kwargs({"post_type": PostType(data_key="type", load_default="topic")}) def get_bookmarks( request: Request, after: Optional[str], diff --git a/tildes/tildes/views/login.py b/tildes/tildes/views/login.py index b6f519d..ef68091 100644 --- a/tildes/tildes/views/login.py +++ b/tildes/tildes/views/login.py @@ -26,7 +26,7 @@ from tildes.views.decorators import not_logged_in, rate_limit_view, use_kwargs @view_config( route_name="login", renderer="login.jinja2", permission=NO_PERMISSION_REQUIRED ) -@use_kwargs({"from_url": String(missing="")}) +@use_kwargs({"from_url": String(load_default="")}) @not_logged_in def get_login(request: Request, from_url: str) -> dict: """Display the login form.""" @@ -65,7 +65,7 @@ def finish_login(request: Request, user: User, redirect_url: str) -> HTTPFound: ), location="form", ) -@use_kwargs({"from_url": String(missing="")}, location="form") +@use_kwargs({"from_url": String(load_default="")}, location="form") @not_logged_in @rate_limit_view("login") def post_login( @@ -148,7 +148,8 @@ def post_login( @not_logged_in @rate_limit_view("login_two_factor") @use_kwargs( - {"code": String(missing=""), "from_url": String(missing="")}, location="form" + {"code": String(load_default=""), "from_url": String(load_default="")}, + location="form", ) def post_login_two_factor(request: Request, code: str, from_url: str) -> NoReturn: """Process a log in request with 2FA.""" diff --git a/tildes/tildes/views/message.py b/tildes/tildes/views/message.py index 05f1452..95ecafe 100644 --- a/tildes/tildes/views/message.py +++ b/tildes/tildes/views/message.py @@ -18,7 +18,7 @@ from tildes.views.decorators import use_kwargs @view_config( route_name="new_message", renderer="new_message.jinja2", permission="message" ) -@use_kwargs({"subject": String(missing=""), "message": String(missing="")}) +@use_kwargs({"subject": String(load_default=""), "message": String(load_default="")}) def get_new_message_form(request: Request, subject: str, message: str) -> dict: """Form for entering a new private message to send.""" return { diff --git a/tildes/tildes/views/register.py b/tildes/tildes/views/register.py index bab4a45..4a44d88 100644 --- a/tildes/tildes/views/register.py +++ b/tildes/tildes/views/register.py @@ -22,7 +22,7 @@ from tildes.views.decorators import not_logged_in, rate_limit_view, use_kwargs @view_config( route_name="register", renderer="register.jinja2", permission=NO_PERMISSION_REQUIRED ) -@use_kwargs({"code": String(missing="")}) +@use_kwargs({"code": String(load_default="")}) @not_logged_in def get_register(request: Request, code: str) -> dict: """Display the registration form.""" diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 376cd8e..336a15d 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -48,7 +48,7 @@ DefaultSettings = namedtuple("DefaultSettings", ["order", "period"]) @view_config(route_name="group_topics", request_method="POST", permission="topic.post") @use_kwargs(TopicSchema(only=("title", "markdown", "link")), location="form") @use_kwargs( - {"tags": String(missing=""), "confirm_repost": Boolean(missing=False)}, + {"tags": String(load_default=""), "confirm_repost": Boolean(load_default=False)}, location="form", ) def post_group_topics( @@ -345,7 +345,7 @@ def get_group_topics( # noqa @view_config(route_name="search", renderer="search.jinja2") @view_config(route_name="group_search", renderer="search.jinja2") @use_kwargs(TopicListingSchema(only=("after", "before", "order", "per_page", "period"))) -@use_kwargs({"search": String(data_key="q", missing="")}) +@use_kwargs({"search": String(data_key="q", load_default="")}) def get_search( request: Request, order: Optional[TopicSortOption], @@ -414,7 +414,7 @@ def get_search( @view_config( route_name="new_topic", renderer="new_topic.jinja2", permission="topic.post" ) -@use_kwargs({"title": String(missing=""), "link": String(missing="")}) +@use_kwargs({"title": String(load_default=""), "link": String(load_default="")}) def get_new_topic_form(request: Request, title: str, link: str) -> dict: """Form for entering a new topic to post.""" group = request.context @@ -424,7 +424,7 @@ def get_new_topic_form(request: Request, title: str, link: str) -> dict: @view_config(route_name="topic", renderer="topic.jinja2") @view_config(route_name="topic_no_title", renderer="topic.jinja2") -@use_kwargs({"comment_order": Enum(CommentTreeSortOption, missing=None)}) +@use_kwargs({"comment_order": Enum(CommentTreeSortOption, load_default=None)}) def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict: """View a single topic.""" topic = request.context diff --git a/tildes/tildes/views/user.py b/tildes/tildes/views/user.py index 71d4695..d9b38e7 100644 --- a/tildes/tildes/views/user.py +++ b/tildes/tildes/views/user.py @@ -25,8 +25,8 @@ from tildes.views.decorators import use_kwargs @use_kwargs(MixedListingSchema()) @use_kwargs( { - "post_type": PostType(data_key="type", missing=None), - "order_name": String(data_key="order", missing="new"), + "post_type": PostType(data_key="type", load_default=None), + "order_name": String(data_key="order", load_default="new"), } ) def get_user( @@ -94,8 +94,8 @@ def get_user( @use_kwargs( { "post_type": PostType(data_key="type", required=True), - "order_name": String(data_key="order", missing="new"), - "search": String(data_key="q", missing=""), + "order_name": String(data_key="order", load_default="new"), + "search": String(data_key="q", load_default=""), } ) def get_user_search( diff --git a/tildes/tildes/views/votes.py b/tildes/tildes/views/votes.py index ba5f798..ffdb619 100644 --- a/tildes/tildes/views/votes.py +++ b/tildes/tildes/views/votes.py @@ -15,7 +15,7 @@ from tildes.views.decorators import use_kwargs @view_config(route_name="votes", renderer="votes.jinja2") @use_kwargs(PaginatedListingSchema()) -@use_kwargs({"post_type": PostType(data_key="type", missing="topic")}) +@use_kwargs({"post_type": PostType(data_key="type", load_default="topic")}) def get_voted_posts( request: Request, after: Optional[str],