Skip to content

Commit

Permalink
Fixing two bugs during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ColtonProvias committed Jun 27, 2016
1 parent 010aa29 commit e47d161
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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*
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 7 additions & 6 deletions sqlalchemy_jsonapi/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
}


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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'}
Expand Down

0 comments on commit e47d161

Please sign in to comment.