sqlalchemy-jsonapi
sqlalchemy-jsonapi copied to clipboard
Getting a TypeError exception on a post_collection call
def post_collection(self, session, data, api_type):
"""
Create a new Resource.
:param session: SQLAlchemy session
:param data: Request JSON Data
:param params: Keyword arguments
"""
model = self._fetch_model(api_type)
self._check_json_data(data)
orm_desc_keys = model.__mapper__.all_orm_descriptors.keys()
if 'type' not in data['data'].keys():
raise MissingTypeError()
if data['data']['type'] != model.__jsonapi_type__:
raise InvalidTypeForEndpointError(
model.__jsonapi_type__, data['data']['type'])
resource = model()
check_permission(resource, None, Permissions.CREATE)
data['data'].setdefault('relationships', {})
data['data'].setdefault('attributes', {})
data_keys = set(map((lambda x: resource.__jsonapi_map_to_py__.get(x, None)), data['data'].get('relationships', {}).keys()))
model_keys = set(resource.__mapper__.relationships.keys())
if not data_keys <= model_keys:
raise BadRequestError(
'{} not relationships for {}'.format(
', '.join(list(data_keys -
> model_keys)), model.__jsonapi_type__))
E TypeError: sequence item 0: expected str instance, NoneType found
.tox/py35/lib/python3.5/site-packages/sqlalchemy_jsonapi/serializer.py:968: TypeError
I was attempting to POST an object with a one-to-many related object and hit this exception. I'm sure I'm doing something wrong as I'm new to jsonapi, but I wish it produced a better error message this.
Can you add the call you were trying to make? And maybe an example of the models/relationship?