Skip to content

Commit

Permalink
4.0.3 - Bugfixes in collection POST
Browse files Browse the repository at this point in the history
  • Loading branch information
ColtonProvias committed Jan 24, 2016
1 parent 80f9b85 commit c830745
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 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.1 - 4.0.3

*2016-01-21*

* Fixed bug where the wrong map was being checked when creating new resource
* Fixed content-length bug when DELETE is provided for resources

## 4.0.0

*2016-01-20*
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.0',
version='4.0.3',
url='http://github.com/coltonprovias/sqlalchemy-jsonapi',
license='MIT',
author='Colton J. Provias',
Expand Down
3 changes: 2 additions & 1 deletion sqlalchemy_jsonapi/flaskext.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def new_view(**kwargs):
if method == Method.GET:
data = request.args
else:
if int(request.headers.get('content-length', 0)) > 0:
content_length = request.headers.get('content-length', 0)
if content_length and int(content_length) > 0:
content_type = request.headers.get('content-type', None)
if content_type != 'application/vnd.api+json':
data = MissingContentTypeError().data
Expand Down
12 changes: 6 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.1'}
'meta': {'sqlalchemy_jsonapi_version': '4.0.3'}
}


Expand Down Expand Up @@ -974,21 +974,21 @@ def post_collection(self, session, data, api_type):

for key, relationship in resource.__mapper__.relationships.items():
attrs_to_ignore |= set(relationship.local_columns) | {key}
py_key = resource.__jsonapi_map_to_py__[key]
api_key = resource.__jsonapi_map_to_api__[key]

if 'relationships' not in data['data'].keys()\
or py_key not in data['data']['relationships'].keys():
or api_key not in data['data']['relationships'].keys():
continue

data_rel = data['data']['relationships'][key]
data_rel = data['data']['relationships'][api_key]
if 'data' not in data_rel.keys():
raise BadRequestError(
'Missing data key in relationship {}'.format(key))
data_rel = data_rel['data']

remote_side = relationship.back_populates
if relationship.direction == MANYTOONE:
setter = get_rel_desc(resource, py_key,
setter = get_rel_desc(resource, key,
RelationshipActions.SET)
if data_rel is None:
setters.append([setter, None])
Expand All @@ -1011,7 +1011,7 @@ def post_collection(self, session, data, api_type):
Permissions.CREATE)
setters.append([setter, to_relate])
else:
setter = get_rel_desc(resource, py_key,
setter = get_rel_desc(resource, key,
RelationshipActions.APPEND)
if not isinstance(data_rel, list):
raise BadRequestError(
Expand Down

0 comments on commit c830745

Please sign in to comment.