Skip to content

Commit 175057c

Browse files
committed
Merge branch 'hotfix-0.12.1' into develop
2 parents 046252f + 16321ea commit 175057c

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

Diff for: docs/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Flask-REST-JSONAPI has lot of features:
2929
* Sparse fieldsets
3030
* Pagination
3131
* Sorting
32-
* OAuth
3332
* Permission management
33+
* OAuth support
3434

3535

3636
User's Guide

Diff for: docs/oauth.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Example ::
4545

4646
If you want to customize the scope you can provide a function that computes your custom scope. The function have to looks like that:
4747

48-
.. code-block:: python
48+
.. code-block:: python
4949
5050
def get_scope(resource, method):
5151
"""Compute the name of the scope for oauth
@@ -80,7 +80,7 @@ If you want to disable OAuth or make custom methods protection for a resource yo
8080

8181
Example:
8282

83-
.. code-block:: python
83+
.. code-block:: python
8484
8585
from flask_rest_jsonapi import ResourceList
8686
from your_project.extensions import oauth2

Diff for: docs/permission.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The permission manager must be a function that looks like this:
4343

4444
If permission is denied I recommand to raise exception like that:
4545

46-
.. code-block:: python
46+
.. code-block:: python
4747
4848
raise JsonApiException(<error_source>,
4949
<error_details>,
@@ -52,7 +52,7 @@ If permission is denied I recommand to raise exception like that:
5252
5353
You can disable the permission system or make custom permission checking management of a resource like that:
5454

55-
.. code-block:: python
55+
.. code-block:: python
5656
5757
from flask_rest_jsonapi import ResourceList
5858
from your_project.extensions import api

Diff for: flask_rest_jsonapi/data_layers/alchemy.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from flask_rest_jsonapi.constants import DEFAULT_PAGE_SIZE
99
from flask_rest_jsonapi.data_layers.base import BaseDataLayer
1010
from flask_rest_jsonapi.exceptions import RelationNotFound, RelatedObjectNotFound, JsonApiException,\
11-
InvalidSort
11+
InvalidSort, ObjectNotFound
1212
from flask_rest_jsonapi.data_layers.filtering.alchemy import create_filters
1313
from flask_rest_jsonapi.schema import get_relationships
1414

@@ -110,6 +110,12 @@ def update_object(self, obj, data, view_kwargs):
110110
:param dict view_kwargs: kwargs from the resource view
111111
:return boolean: True if object have changed else False
112112
"""
113+
if obj is None:
114+
url_field = getattr(self, 'url_field', 'id')
115+
filter_value = view_kwargs[url_field]
116+
raise ObjectNotFound({'parameter': url_field},
117+
'{}: {} not found'.format(self.model.__class__.__name__, filter_value))
118+
113119
self.before_update_object(obj, data, view_kwargs)
114120

115121
relationship_fields = get_relationships(self.resource.schema)
@@ -133,6 +139,12 @@ def delete_object(self, obj, view_kwargs):
133139
:param DeclarativeMeta item: an item from sqlalchemy
134140
:param dict view_kwargs: kwargs from the resource view
135141
"""
142+
if obj is None:
143+
url_field = getattr(self, 'url_field', 'id')
144+
filter_value = view_kwargs[url_field]
145+
raise ObjectNotFound({'parameter': url_field},
146+
'{}: {} not found'.format(self.model.__class__.__name__, filter_value))
147+
136148
self.before_delete_object(obj, view_kwargs)
137149

138150
self.session.delete(obj)
@@ -157,6 +169,12 @@ def create_relationship(self, json_data, relationship_field, related_id_field, v
157169

158170
obj = self.get_object(view_kwargs)
159171

172+
if obj is None:
173+
url_field = getattr(self, 'url_field', 'id')
174+
filter_value = view_kwargs[url_field]
175+
raise ObjectNotFound({'parameter': url_field},
176+
'{}: {} not found'.format(self.model.__class__.__name__, filter_value))
177+
160178
if not hasattr(obj, relationship_field):
161179
raise RelationNotFound('', "{} has no attribute {}".format(obj.__class__.__name__, relationship_field))
162180

@@ -207,6 +225,12 @@ def get_relationship(self, relationship_field, related_type_, related_id_field,
207225

208226
obj = self.get_object(view_kwargs)
209227

228+
if obj is None:
229+
url_field = getattr(self, 'url_field', 'id')
230+
filter_value = view_kwargs[url_field]
231+
raise ObjectNotFound({'parameter': url_field},
232+
'{}: {} not found'.format(self.model.__class__.__name__, filter_value))
233+
210234
if not hasattr(obj, relationship_field):
211235
raise RelationNotFound('', "{} has no attribute {}".format(obj.__class__.__name__, relationship_field))
212236

@@ -237,6 +261,12 @@ def update_relationship(self, json_data, relationship_field, related_id_field, v
237261

238262
obj = self.get_object(view_kwargs)
239263

264+
if obj is None:
265+
url_field = getattr(self, 'url_field', 'id')
266+
filter_value = view_kwargs[url_field]
267+
raise ObjectNotFound({'parameter': url_field},
268+
'{}: {} not found'.format(self.model.__class__.__name__, filter_value))
269+
240270
if not hasattr(obj, relationship_field):
241271
raise RelationNotFound('', "{} has no attribute {}".format(obj.__class__.__name__, relationship_field))
242272

@@ -290,6 +320,12 @@ def delete_relationship(self, json_data, relationship_field, related_id_field, v
290320

291321
obj = self.get_object(view_kwargs)
292322

323+
if obj is None:
324+
url_field = getattr(self, 'url_field', 'id')
325+
filter_value = view_kwargs[url_field]
326+
raise ObjectNotFound({'parameter': url_field},
327+
'{}: {} not found'.format(self.model.__class__.__name__, filter_value))
328+
293329
if not hasattr(obj, relationship_field):
294330
raise RelationNotFound('', "{} has no attribute {}".format(obj.__class__.__name__, relationship_field))
295331

Diff for: flask_rest_jsonapi/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class JsonApiException(Exception):
55

6-
title = 'Unknow error'
6+
title = 'Unknown error'
77
status = 500
88

99
def __init__(self, source, detail, title=None, status=None):

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33

4-
__version__ = '0.12.0'
4+
__version__ = '0.12.1'
55

66

77
setup(

Diff for: tests/test_sqlalchemy_data_layer.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from flask_rest_jsonapi.data_layers.alchemy import SqlalchemyDataLayer
2020
from flask_rest_jsonapi.data_layers.base import BaseDataLayer
2121
from flask_rest_jsonapi.data_layers.filtering.alchemy import Node
22-
from flask_rest_jsonapi.schema import get_relationships
2322
import flask_rest_jsonapi.decorators
2423
import flask_rest_jsonapi.resource
2524
import flask_rest_jsonapi.schema
@@ -297,7 +296,7 @@ def api_blueprint(client):
297296
def register_routes(client, app, api_blueprint, person_list, person_detail, person_computers,
298297
person_list_raise_jsonapiexception, person_list_raise_exception, person_list_response,
299298
person_list_without_schema, computer_list, computer_detail, computer_owner):
300-
api = Api(api_blueprint)
299+
api = Api(blueprint=api_blueprint)
301300
api.route(person_list, 'person_list', '/persons')
302301
api.route(person_detail, 'person_detail', '/persons/<int:person_id>')
303302
api.route(person_computers, 'person_computers', '/persons/<int:person_id>/relationships/computers')
@@ -423,12 +422,8 @@ def test_compute_schema(person_schema):
423422
query_string = {'page[number]': '3', 'fields[person]': list()}
424423
qsm = QSManager(query_string, person_schema)
425424
with pytest.raises(InvalidInclude):
426-
flask_rest_jsonapi.schema.compute_schema(
427-
person_schema, dict(), qsm, ['id']
428-
)
429-
s = flask_rest_jsonapi.schema.compute_schema(
430-
person_schema, dict(only=list()), qsm, list()
431-
)
425+
flask_rest_jsonapi.schema.compute_schema(person_schema, dict(), qsm, ['id'])
426+
flask_rest_jsonapi.schema.compute_schema(person_schema, dict(only=list()), qsm, list())
432427

433428

434429
# test good cases
@@ -919,6 +914,7 @@ def commit_mock():
919914
def test_sqlalchemy_data_layer_delete_object_error(session, person_model, person_list, monkeypatch):
920915
def commit_mock():
921916
raise JsonApiException()
917+
922918
def delete_mock(obj):
923919
pass
924920
with pytest.raises(JsonApiException):
@@ -1520,5 +1516,5 @@ def test_api(app, person_list):
15201516

15211517
def test_api_resources(app, person_list):
15221518
api = Api()
1523-
api.route(person_list, 'person_list', '/persons', '/person_list')
1519+
api.route(person_list, 'person_list2', '/persons', '/person_list')
15241520
api.init_app(app)

0 commit comments

Comments
 (0)