Skip to content

Conversation

@vladmunteanu
Copy link

@vladmunteanu vladmunteanu commented Mar 11, 2019

After issuing a request to an endpoint like /<resource_a>/<id>/relationships/<resource_b>/ , the resource_b field is not identified as a relationship.
I'm pretty sure the following line is causing the issue:

relationship_field = request.path.split('/')[-1].replace('-', '_')

This is because the last item of request.path.split('/') is actually an empty string:

>>> s = '/api/users/5/relationships/organization/'
>>> s.split('/')
['', 'api', 'users', '5', 'relationships', 'organization', '']
>>> s = '/api/users/5/relationships/organization'
>>> s.split('/')
['', 'api', 'users', '5', 'relationships', 'organization']

@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 92.078% when pulling 133aa44 on vladmunteanu:master into ad3f90f on miLibris:master.

@vladmunteanu
Copy link
Author

You can view a minimal example here: https://github.com/vladmunteanu/apiex-flask-rest-jsonapi
For this project, the relationship management will not work because of this issue.

"""Get useful data for relationship management"""
relationship_field = request.path.split('/')[-1].replace('-', '_')
url = request.path.rstrip('/')
relationship_field = url.split('/')[-1].replace('-', '_')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not good because you split on a list so it doesn't works ?

@vladmunteanu
Copy link
Author

Thanks for checking this @akira-dev, but honestly i wasn't right to begin with. That kind of URL should not have a leading slash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants