diff --git a/CHANGES.md b/CHANGES.md index b0782a9..71cd9e0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # SQLAlchemy-JSONAPI Changelog +## 4.0.9 + +*Unreleased* + +* Fixed bug during testing in delete_relationship where returned resource was missing data key +* Fixed bug during testing in patch_resource where field check was failing + ## 4.0.8 *2016-04-32* diff --git a/setup.py b/setup.py index b4672c9..4f72f56 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ requirements.append('enum34') setup(name='SQLAlchemy-JSONAPI', - version='4.0.8', + version='4.0.9', 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 3095b82..16dcef1 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.8'} + 'meta': {'sqlalchemy_jsonapi_version': '4.0.9'} } @@ -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 = [] + response.data = {'data': []} session.add(resource) @@ -884,12 +884,13 @@ def patch_resource(self, session, json_data, api_type, obj_id): json_data['data'].setdefault('relationships', {}) json_data['data'].setdefault('attributes', {}) - 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: + missing_keys = set(json_data['data'].get('relationships', {}).keys()) \ + - set(resource.__jsonapi_map_to_py__.keys()) + + if missing_keys: raise BadRequestError( '{} not relationships for {}.{}'.format( - ', '.join(list(data_keys - model_keys)), + ', '.join(list(missing_keys)), model.__jsonapi_type__, resource.id)) attrs_to_ignore = {'__mapper__', 'id'}