Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a new relationship via the API throws exception. #897

Closed
oliverroick opened this issue Nov 4, 2016 · 1 comment
Closed

Creating a new relationship via the API throws exception. #897

oliverroick opened this issue Nov 4, 2016 · 1 comment

Comments

@oliverroick
Copy link
Member

Steps to reproduce the error

Try creating a new tenure relationship via the API; use POST /api/v1/organizations/{organization_slug}/projects/{project_slug}/relationships/tenure/

Actual behavior

jsonattrs throws exception AttributeError: 'str' object has no attribute 'keys'. It seems that the attributes JSON is provided as a string instead of a dict. See Opbeat error E#30 on Platform-staging for more context information.

Expected behavior

A new relationship is created, 201 response including relationship details should be returned.

@oliverroick oliverroick added the bug label Nov 5, 2016
@ian-ross ian-ross self-assigned this Nov 8, 2016
@ian-ross
Copy link
Contributor

ian-ross commented Nov 8, 2016

It seems like this might be something to do with formatting of JSON POST bodies by the API explorer being used here. It may be that it's providing a structured JSON object for the attributes as a string. For instance, using HTTPie, something like this works (using a form with some relationship attributes that include a test_int field):

http http://localhost:8000/api/v1/organizations/cadasta/projects/cadasta-myanmar-test-project/relationships/tenure/ party=yts2y5quwz8itx339x8bmm9g spatial_unit=zseg35crrrcrwx5sb35vwr63 tenure_type=CR attributes:='{"test_int": 35}' Authorization:"Token 979606729b554388d8ad52f839af21eb6f8f058c"

Note that the attributes argument to HTTPie is written as attributes:=blah instead of just attributes=blah. That forces HTTPie to interpret the value after the := as structured JSON data, not just a string. I'm guessing that if you use one of the browser API explorer things, it might be harder to get it to send structured data in the request body. If that data (which should be a dictionary) really is being sent as a string, that would explain the error being generated here.

Assigning to Oliver to check and document.

@ian-ross ian-ross assigned oliverroick and unassigned ian-ross Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants