Skip to content

Fix TypeError crash when POST data is not a dict#3636

Merged
leplatrem merged 3 commits intoKinto:mainfrom
chen0427ok:fix-issue-3606-json-validation
Feb 4, 2026
Merged

Fix TypeError crash when POST data is not a dict#3636
leplatrem merged 3 commits intoKinto:mainfrom
chen0427ok:fix-issue-3606-json-validation

Conversation

@chen0427ok
Copy link
Contributor

Summary

Fixes #3606

  • When posting to /records endpoint with data that is not a dictionary (e.g., {"data": ""}), the server would crash with TypeError: list indices must be integers or slices, not str instead of returning a proper 400 validation error.
  • Added TypeError to the exception handling in object_id property at kinto/core/resource/__init__.py:265
  • Added regression test to ensure 400 is returned instead of 500

Test plan

  • Added unit test test_post_raises_400_if_data_is_not_a_dict
  • All existing tests pass
  • Manually verified with httpie commands from the issue

When posting to /records endpoint with data that is not a dictionary
(e.g., {"data": ""}), the server would crash with a TypeError instead
of returning a proper 400 validation error.

Added TypeError to the exception handling in object_id property.
Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

💯
Thank you!
Don't hesitate to add yourself in the contributors file if you like

Copy link
Member

@Natim Natim left a comment

Choose a reason for hiding this comment

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

🎉

@leplatrem leplatrem added the bug label Feb 3, 2026
@leplatrem
Copy link
Contributor

@chen0427ok could you please make format in your branch so that lint and test pass please?

@chen0427ok
Copy link
Contributor Author

@chen0427ok could you please make format in your branch so that lint and test pass please?

Sure! I've reformatted the code.

@leplatrem leplatrem merged commit 15fd62e into Kinto:main Feb 4, 2026
12 checks passed
@leplatrem
Copy link
Contributor

Thank you 🎉

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash with TypeError: list indices must be integers or slices, not str

3 participants

Comments