Skip to content

Commit 87ca872

Browse files
authored
Merge pull request #20 from etiennecaldo/develop
fix(schema): container has been renamed to inner in marshmallow 3.0.0rc8.
2 parents 17e4a23 + 07d9bf9 commit 87ca872

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

flask_combo_jsonapi/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def get_nested_fields(schema, model_field=False):
108108

109109
nested_fields = []
110110
for (key, value) in schema._declared_fields.items():
111-
if isinstance(value, List) and isinstance(value.container, Nested) \
112-
and not isinstance(value.container, Relationship):
111+
if isinstance(value, List) and isinstance(value.inner, Nested) \
112+
and not isinstance(value.inner, Relationship):
113113
nested_fields.append(key)
114114
elif isinstance(value, Nested) and not isinstance(value, Relationship):
115115
nested_fields.append(key)

tests/test_sqlalchemy_data_layer.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class StringJsonAttributePerson(base):
9898
# This model uses a String type for "json_tags" to avoid dependency on a nonstandard SQL type in testing, \
9999
# while still demonstrating support
100100
address = Column(MagicJSON)
101+
tags = Column(MagicJSON)
101102

102103
yield StringJsonAttributePerson
103104

@@ -136,7 +137,10 @@ class Computer(base):
136137

137138

138139
@pytest.fixture(scope="module")
139-
def engine(person_tag_model, person_single_tag_model, person_model, computer_model, string_json_attribute_person_model):
140+
def engine(
141+
person_tag_model, person_single_tag_model, person_model,
142+
computer_model, string_json_attribute_person_model
143+
):
140144
engine = create_engine("sqlite:///:memory:")
141145
person_tag_model.metadata.create_all(engine)
142146
person_single_tag_model.metadata.create_all(engine)
@@ -245,6 +249,7 @@ class Meta:
245249
name = fields.Str(required=True)
246250
birth_date = fields.DateTime()
247251
address = fields.Nested(address_schema, many=False)
252+
tags = fields.List(fields.Dict())
248253

249254
yield StringJsonAttributePersonSchema
250255

@@ -774,6 +779,35 @@ def test_post_list_nested(client, register_routes, computer):
774779
assert response.status_code == 201
775780
assert json.loads(response.get_data())["data"]["attributes"]["tags"][0]["key"] == "k1"
776781

782+
def test_post_list_nested_field(client, register_routes):
783+
"""
784+
Test a schema contains a nested field is correctly serialized and deserialized
785+
"""
786+
payload = {
787+
'data': {
788+
'type': 'string_json_attribute_person',
789+
'attributes': {
790+
'name': 'test',
791+
'tags': [
792+
{'key': 'new_key', 'value': 'new_value'}
793+
],
794+
},
795+
}
796+
}
797+
with client:
798+
response = client.post(
799+
'/string_json_attribute_persons',
800+
data=json.dumps(payload),
801+
content_type='application/vnd.api+json'
802+
)
803+
assert response.status_code == 201, response.json['errors']
804+
assert json.loads(
805+
response.get_data()
806+
)['data']['attributes']['tags'][0]['key'] == 'new_key'
807+
assert json.loads(
808+
response.get_data()
809+
)['data']['attributes']['tags'][0]['value'] == 'new_value'
810+
777811

778812
def test_post_list_single(client, register_routes, person):
779813
payload = {

0 commit comments

Comments
 (0)