diff --git a/AUTHORS.rst b/AUTHORS.rst index b32babb..108d189 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -33,3 +33,4 @@ Contributors (chronological) - Areeb Jamal `@iamareebjamal `_ - Suren Khorenyan `@mahenzon `_ - Karthikeyan Singaravelan `@tirkarthi `_ +- Vlad Munteanu `@vladmunteanu https://github.com/vladmunteanu/` diff --git a/marshmallow_jsonapi/fields.py b/marshmallow_jsonapi/fields.py index 0e16527..62aac21 100644 --- a/marshmallow_jsonapi/fields.py +++ b/marshmallow_jsonapi/fields.py @@ -152,7 +152,9 @@ def schema(self): def get_related_url(self, obj): if self.related_url: - params = resolve_params(obj, self.related_url_kwargs, default=self.default) + params = resolve_params( + obj, self.related_url_kwargs, default=self.dump_default + ) non_null_params = { key: value for key, value in params.items() if value is not None } @@ -162,7 +164,9 @@ def get_related_url(self, obj): def get_self_url(self, obj): if self.self_url: - params = resolve_params(obj, self.self_url_kwargs, default=self.default) + params = resolve_params( + obj, self.self_url_kwargs, default=self.dump_default + ) non_null_params = { key: value for key, value in params.items() if value is not None } diff --git a/marshmallow_jsonapi/flask.py b/marshmallow_jsonapi/flask.py index afb095e..fd807de 100644 --- a/marshmallow_jsonapi/flask.py +++ b/marshmallow_jsonapi/flask.py @@ -119,7 +119,7 @@ def __init__( def get_url(self, obj, view_name, view_kwargs): if view_name: - kwargs = resolve_params(obj, view_kwargs, default=self.default) + kwargs = resolve_params(obj, view_kwargs, default=self.dump_default) kwargs["endpoint"] = view_name try: return flask.url_for(**kwargs) diff --git a/tests/base.py b/tests/base.py index 6958d67..78bc992 100644 --- a/tests/base.py +++ b/tests/base.py @@ -100,7 +100,7 @@ class Meta: class PostSchema(Schema): id = fields.Str() - post_title = fields.Str(attribute="title", dump_to="title", data_key="title") + post_title = fields.Str(attribute="title", data_key="title") author = fields.Relationship( "http://test.test/posts/{id}/author/", @@ -114,8 +114,6 @@ class PostSchema(Schema): "http://test.test/posts/{id}/comments/", related_url_kwargs={"id": ""}, attribute="comments", - load_from="post-comments", - dump_to="post-comments", data_key="post-comments", schema="CommentSchema", many=True, @@ -126,7 +124,6 @@ class PostSchema(Schema): "http://test.test/posts/{id}/keywords/", related_url_kwargs={"id": ""}, attribute="keywords", - dump_to="post-keywords", data_key="post-keywords", schema="KeywordSchema", many=True, diff --git a/tests/test_fields.py b/tests/test_fields.py index 3203b2c..96f951e 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -353,7 +353,7 @@ def test_empty_relationship_with_alternative_identifier_field( field = Relationship( related_url="/authors/{author_id}", related_url_kwargs={"author_id": ""}, - default=None, + dump_default=None, ) result = field.serialize("author", post_with_null_author) diff --git a/tests/test_flask.py b/tests/test_flask.py index 0ca1f66..99cc2a8 100644 --- a/tests/test_flask.py +++ b/tests/test_flask.py @@ -52,7 +52,7 @@ class PostAuthorFlaskSchema(Schema): field = Relationship( related_view="author_detail", related_view_kwargs={"author_id": ""}, - default=None, + dump_default=None, ) class Meta: @@ -166,7 +166,7 @@ def test_empty_relationship_with_alternative_identifier_field( field = Relationship( related_view="author_detail", related_view_kwargs={"author_id": ""}, - default=None, + dump_default=None, ) result = field.serialize("author", post_with_null_author) diff --git a/tests/test_options.py b/tests/test_options.py index b4b88c0..5fd2c72 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -24,7 +24,7 @@ class Meta: class AuthorSchemaWithOverrideInflection(Schema): id = fields.Str(dump_only=True) # data_key and load_from takes precedence over inflected attribute - first_name = fields.Str(data_key="firstName", load_from="firstName") + first_name = fields.Str(data_key="firstName") last_name = fields.Str() class Meta: diff --git a/tests/test_schema.py b/tests/test_schema.py index 7373cbe..19aeeb0 100755 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -224,7 +224,7 @@ class PostClassSchema(PostSchema): "http://test.test/posts/{id}/comments/", related_url_kwargs={"id": ""}, attribute="comments", - dump_to="post-comments", + data_key="post-comments", schema=CommentSchema, many=True, ) @@ -306,7 +306,6 @@ class PostInnerSchemalessSchema(Schema): "http://test.test/posts/{id}/comments/", related_url_kwargs={"id": ""}, data_key="post-comments", - load_from="post-comments", many=True, type_="comments", ) @@ -834,14 +833,14 @@ class ArticleMissingParamSchema(Schema): include_resource_linkage=True, many=False, type_="people", - missing="1", + load_default="1", ) comments = fields.Relationship( dump_only=False, include_resource_linkage=True, many=True, type_="comments", - missing=["2", "3"], + load_default=["2", "3"], ) class Meta: