diff --git a/CHANGES.md b/CHANGES.md index 4e4ace5..ab8e32b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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* diff --git a/setup.py b/setup.py index 6c99dfc..5c6bd66 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/sqlalchemy_jsonapi/flaskext.py b/sqlalchemy_jsonapi/flaskext.py index 94a8a9b..2548d32 100644 --- a/sqlalchemy_jsonapi/flaskext.py +++ b/sqlalchemy_jsonapi/flaskext.py @@ -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 diff --git a/sqlalchemy_jsonapi/serializer.py b/sqlalchemy_jsonapi/serializer.py index 48463d2..5e24c11 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.1'} + 'meta': {'sqlalchemy_jsonapi_version': '4.0.3'} } @@ -974,13 +974,13 @@ 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)) @@ -988,7 +988,7 @@ def post_collection(self, session, data, api_type): 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]) @@ -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(