From d2b979675096bbfee6e3ec89f206bd9fa1e8935d Mon Sep 17 00:00:00 2001 From: Nicolas Graves <76450848+nicolas-graves@users.noreply.github.com> Date: Wed, 24 Dec 2025 13:09:54 +0100 Subject: [PATCH] Drop support for marshmallow < 3 --- flask_combo_jsonapi/data_layers/alchemy.py | 5 ++--- flask_combo_jsonapi/schema.py | 5 ++--- tests/test_sqlalchemy_data_layer.py | 15 +++------------ 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/flask_combo_jsonapi/data_layers/alchemy.py b/flask_combo_jsonapi/data_layers/alchemy.py index 4f8e5e3..6ec510b 100644 --- a/flask_combo_jsonapi/data_layers/alchemy.py +++ b/flask_combo_jsonapi/data_layers/alchemy.py @@ -9,8 +9,7 @@ from sqlalchemy.inspection import inspect from sqlalchemy.orm.attributes import QueryableAttribute from sqlalchemy.orm import joinedload, ColumnProperty, RelationshipProperty -from marshmallow import class_registry -from marshmallow.base import SchemaABC +from marshmallow import class_registry, Schema from flask_combo_jsonapi.data_layers.base import BaseDataLayer from flask_combo_jsonapi.data_layers.sorting.alchemy import create_sorts @@ -683,7 +682,7 @@ def eagerload_includes(self, query, qs): related_schema_cls = get_related_schema(current_schema, obj) - if isinstance(related_schema_cls, SchemaABC): + if isinstance(related_schema_cls, Schema): related_schema_cls = related_schema_cls.__class__ else: related_schema_cls = class_registry.get_class(related_schema_cls) diff --git a/flask_combo_jsonapi/schema.py b/flask_combo_jsonapi/schema.py index 9d24afc..3c98c86 100644 --- a/flask_combo_jsonapi/schema.py +++ b/flask_combo_jsonapi/schema.py @@ -1,8 +1,7 @@ """Helpers to deal with marshmallow schemas""" from collections import OrderedDict -from marshmallow import class_registry -from marshmallow.base import SchemaABC +from marshmallow import class_registry, Schema from marshmallow_jsonapi.fields import Relationship, List, Nested from flask_combo_jsonapi.exceptions import InvalidInclude @@ -70,7 +69,7 @@ def compute_schema(schema_cls, default_kwargs, qs, include): related_schema_kwargs = {} if 'context' in default_kwargs: related_schema_kwargs['context'] = default_kwargs['context'] - if isinstance(related_schema_cls, SchemaABC): + if isinstance(related_schema_cls, Schema): related_schema_kwargs['many'] = related_schema_cls.many related_schema_kwargs['include_data'] = related_schema_cls.__dict__.get('include_data') related_schema_cls = related_schema_cls.__class__ diff --git a/tests/test_sqlalchemy_data_layer.py b/tests/test_sqlalchemy_data_layer.py index d9fdbe8..e71c66f 100644 --- a/tests/test_sqlalchemy_data_layer.py +++ b/tests/test_sqlalchemy_data_layer.py @@ -305,7 +305,7 @@ def address_schema(): class AddressSchema(MarshmallowSchema): street = fields.String(required=True) city = fields.String(required=True) - state = fields.String(missing="NC") + state = fields.String(load_default="NC") zip = fields.String(required=True) yield AddressSchema @@ -401,8 +401,8 @@ class Meta: serial = fields.Str(required=True) owner = Relationship( attribute="person", - default=None, - missing=None, + dump_default=None, + load_default=None, related_view="api.person_detail", related_view_kwargs={"person_id": ""}, schema="PersonSchema", @@ -819,15 +819,6 @@ def test_compute_schema(person_schema): flask_combo_jsonapi.schema.compute_schema(person_schema, dict(only=list()), qsm, list()) -def test_compute_schema_propagate_context(person_schema, computer_schema): - query_string = {} - qsm = QSManager(query_string, person_schema) - schema = flask_combo_jsonapi.schema.compute_schema(person_schema, dict(), qsm, ["computers"]) - assert schema.declared_fields["computers"].__dict__["_Relationship__schema"].__dict__["context"] == dict() - schema = flask_combo_jsonapi.schema.compute_schema(person_schema, dict(context=dict(foo="bar")), qsm, ["computers"]) - assert schema.declared_fields["computers"].__dict__["_Relationship__schema"].__dict__["context"] == dict(foo="bar") - - # test good cases def test_get_list(client, register_routes, person, person_2): with client: