Skip to content

Commit 9eeae3d

Browse files
committed
Python 3 and Marshmallow 3
1 parent b44bc08 commit 9eeae3d

File tree

4 files changed

+167
-97
lines changed

4 files changed

+167
-97
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
dist: trusty
22
language: python
33
python:
4-
- '2.7'
54
- '3.4'
65
- '3.5'
7-
- 'pypy'
6+
- '3.6'
7+
- 'pypy3'
88
install:
99
- pip install -r requirements.txt
1010
- pip install coveralls coverage

flask_rest_jsonapi/resource.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def get(self, *args, **kwargs):
128128
qs,
129129
qs.include)
130130

131-
result = schema.dump(objects).data
131+
result = schema.dump(objects)
132132

133133
view_kwargs = request.view_args if getattr(self, 'view_kwargs', None) is True else dict()
134134
add_pagination_links(result,
@@ -155,7 +155,7 @@ def post(self, *args, **kwargs):
155155
qs.include)
156156

157157
try:
158-
data, errors = schema.load(json_data)
158+
data = schema.load(json_data)
159159
except IncorrectTypeError as e:
160160
errors = e.messages
161161
for error in errors['errors']:
@@ -169,17 +169,11 @@ def post(self, *args, **kwargs):
169169
message['title'] = "Validation error"
170170
return errors, 422
171171

172-
if errors:
173-
for error in errors['errors']:
174-
error['status'] = "422"
175-
error['title'] = "Validation error"
176-
return errors, 422
177-
178172
self.before_post(args, kwargs, data=data)
179173

180174
obj = self.create_object(data, kwargs)
181175

182-
result = schema.dump(obj).data
176+
result = schema.dump(obj)
183177

184178
if result['data'].get('links', {}).get('self'):
185179
final_result = (result, 201, {'Location': result['data']['links']['self']})
@@ -235,7 +229,7 @@ def get(self, *args, **kwargs):
235229
qs,
236230
qs.include)
237231

238-
result = schema.dump(obj).data
232+
result = schema.dump(obj)
239233

240234
final_result = self.after_get(result)
241235

@@ -258,7 +252,7 @@ def patch(self, *args, **kwargs):
258252
qs.include)
259253

260254
try:
261-
data, errors = schema.load(json_data)
255+
data = schema.load(json_data)
262256
except IncorrectTypeError as e:
263257
errors = e.messages
264258
for error in errors['errors']:
@@ -272,12 +266,6 @@ def patch(self, *args, **kwargs):
272266
message['title'] = "Validation error"
273267
return errors, 422
274268

275-
if errors:
276-
for error in errors['errors']:
277-
error['status'] = "422"
278-
error['title'] = "Validation error"
279-
return errors, 422
280-
281269
if 'id' not in json_data['data']:
282270
raise BadRequest('Missing id in "data" node',
283271
source={'pointer': '/data/id'})
@@ -289,7 +277,7 @@ def patch(self, *args, **kwargs):
289277

290278
obj = self.update_object(data, qs, kwargs)
291279

292-
result = schema.dump(obj).data
280+
result = schema.dump(obj)
293281

294282
final_result = self.after_patch(result)
295283

@@ -373,7 +361,7 @@ def get(self, *args, **kwargs):
373361
schema = compute_schema(self.schema, dict(), qs, qs.include)
374362

375363
serialized_obj = schema.dump(obj)
376-
result['included'] = serialized_obj.data.get('included', dict())
364+
result['included'] = serialized_obj.get('included', dict())
377365

378366
final_result = self.after_get(result)
379367

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from setuptools import setup, find_packages
22

3-
43
__version__ = '0.30.1'
54

6-
75
setup(
86
name="Flask-REST-JSONAPI",
97
version=__version__,
@@ -26,11 +24,13 @@
2624
packages=find_packages(exclude=['tests']),
2725
zip_safe=False,
2826
platforms='any',
29-
install_requires=['six',
30-
'Flask>=0.11',
31-
'marshmallow==2.18.0',
32-
'marshmallow_jsonapi',
33-
'sqlalchemy'],
27+
install_requires=[
28+
'six',
29+
'Flask>=0.11',
30+
'marshmallow>=3.1.0',
31+
'marshmallow_jsonapi>=0.11.0',
32+
'sqlalchemy'
33+
],
3434
setup_requires=['pytest-runner'],
3535
tests_require=['pytest'],
3636
extras_require={'tests': 'pytest', 'docs': 'sphinx'}

0 commit comments

Comments
 (0)