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

Missing "description" request body parameter in API causes 500 #78

Closed
bachya opened this issue Feb 18, 2021 · 2 comments · Fixed by #81
Closed

Missing "description" request body parameter in API causes 500 #78

bachya opened this issue Feb 18, 2021 · 2 comments · Fixed by #81

Comments

@bachya
Copy link
Contributor

bachya commented Feb 18, 2021

Version: 1.3.1
Architecture: Docker

When I attempt to omit the description request body parameter in the POST /api/bookmarks/ API call, I get a 500 response. The API should either instruct me to include this field or gracefully handle its absence.

@bachya bachya changed the title Missing "description" request body parameter causes 500 Missing "description" request body parameter in API causes 500 Feb 18, 2021
@sissbruecker
Copy link
Owner

sissbruecker commented Feb 18, 2021

Looked into it, there's two issues here:

  • validation on the endpoint is not correctly defined
  • model validation allows blank, but not null values for title, description

For now the minimal payload for creating bookmarks would be:

{
    "url": "https://github.com/sissbruecker/linkding/issues/78",
    "title": "",
    "description": "",
    "tag_names": []
}

@sissbruecker
Copy link
Owner

Marked the respective fields as optional in the serializer. The minimal payload is now:

{
    "url": "https://github.com/sissbruecker/linkding/issues/78"
}

Note that empy text fields (title, description) are represented by an empty string "" instead of null. That is the best practice recommended by Django. As such it is OK to omit the field, pass an empty string or a full string. But it is not allowed to set the JSON property to null. Also all empty text fields will be returned as empty string, even if you did not pass a value for it.

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 a pull request may close this issue.

2 participants