Skip to content

Report the reason when object creation fails - #99

Open
ramonski wants to merge 2 commits into
feature/rest-verbsfrom
feature/report-create-errors
Open

Report the reason when object creation fails#99
ramonski wants to merge 2 commits into
feature/rest-verbsfrom
feature/report-create-errors

Conversation

@ramonski

Copy link
Copy Markdown
Contributor

What

create_items now includes the underlying error(s) in its response when nothing could be created, instead of the generic "No Objects could be created".

Why

When an object failed to create, create_items caught the exception, logged it, and raised a generic BadRequestError("No Objects could be created") — discarding the actual reason. For example, creating an AnalysisCategory without its required department field produced only:

No Objects could be created

while the real cause was right there in the logs:

Error while creating object: {"department": "required field"}

Callers (including agents driving the API) had to dig through server logs to find out which required fields were missing.

Change

create_items collects the per-object error messages and surfaces them in the raised error:

No objects could be created: {"department": "required field"}

The authoritative validation detail comes straight from SENAITE, so there is no duplicated list of required fields to maintain. Per-object savepoint rollback and the partial-success path (return whatever succeeded) are unchanged.

Stacking

Stacked on top of #98 (feature/rest-verbs).

ramonski added 2 commits July 27, 2026 11:54
create_items caught each object's creation error, logged it, and then
raised a generic "No Objects could be created", discarding the useful
detail (for example the validation error {"field": "required field"}).
Collect the per-object errors and include them in the raised message so
callers see exactly what to fix instead of a generic failure.
@ramonski
ramonski requested a review from xispa July 27, 2026 09:56
@ramonski ramonski added the Enhancement ✨ Improvement to existing functionality label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement ✨ Improvement to existing functionality

Development

Successfully merging this pull request may close these issues.

1 participant