diff --git a/CHANGES.md b/CHANGES.md index 7027a0e..b0782a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,10 +1,18 @@ # SQLAlchemy-JSONAPI Changelog -## 4.0.5 +## 4.0.8 + +*2016-04-32* + +* Fixed bug with relationship not being found during resource patch. + +## 4.0.5 - 4.0.7 *2016-03-20* * Fixed missing jsonapi_permissions attribute when patching relationships. +* Fixed AttributeError on GET related of a NoneType. +* Fixed where meta was now always being injected into non-204 responses. ## 4.0.4 diff --git a/setup.py b/setup.py index 969b08b..b4672c9 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ requirements.append('enum34') setup(name='SQLAlchemy-JSONAPI', - version='4.0.5', + version='4.0.8', url='http://github.com/coltonprovias/sqlalchemy-jsonapi', license='MIT', author='Colton J. Provias', diff --git a/sqlalchemy_jsonapi/serializer.py b/sqlalchemy_jsonapi/serializer.py index d2a002c..3095b82 100644 --- a/sqlalchemy_jsonapi/serializer.py +++ b/sqlalchemy_jsonapi/serializer.py @@ -140,7 +140,7 @@ def __init__(self): self.status_code = 200 self.data = { 'jsonapi': {'version': '1.0'}, - 'meta': {'sqlalchemy_jsonapi_version': '4.0.5'} + 'meta': {'sqlalchemy_jsonapi_version': '4.0.8'} } @@ -548,7 +548,7 @@ def delete_relationship(self, session, data, api_type, obj_id, rel_key): return ToManyExpectedError(model, resource, relationship) response = JSONAPIResponse() - response.data = {'data': []} + response.data = [] session.add(resource) @@ -648,7 +648,7 @@ def get_collection(self, session, query, api_key): start, end = self._parse_page(query) response = JSONAPIResponse() - response.data = {'data': []} + response.data['data'] = [] for instance in collection: try: @@ -714,8 +714,11 @@ def get_related(self, session, query, api_type, obj_id, rel_key): if relationship.direction == MANYTOONE: try: - response.data['data'] = self._render_full_resource(related, - {}, {}) + if related is None: + response.data['data'] = None + else: + response.data['data'] = self._render_full_resource(related, + {}, {}) except PermissionDeniedError: response.data['data'] = None else: @@ -881,7 +884,7 @@ def patch_resource(self, session, json_data, api_type, obj_id): json_data['data'].setdefault('relationships', {}) json_data['data'].setdefault('attributes', {}) - data_keys = set(json_data['data']['relationships'].keys()) + data_keys = set(map((lambda x: resource.__jsonapi_map_to_py__.get(x, None)), json_data['data'].get('relationships', {}).keys())) model_keys = set(resource.__mapper__.relationships.keys()) if not data_keys <= model_keys: raise BadRequestError(