langgenius/dify · warning · ValueError

invalid_param

invalid_param

Error message

rating cannot be None when feedback not exists

What it means

ValueError (code=invalid_param) raised in _update_message_feedback (message.py:486) when the client sends no rating AND there is no existing feedback to delete. The handler treats a missing rating as 'delete existing feedback'; with nothing to delete, the request is contradictory. Flask surfaces this as a 400.

Source

Thrown at api/controllers/console/app/message.py:486

def _update_message_feedback(*, session: Session, current_user: Account, app_model: App):
    args = MessageFeedbackPayload.model_validate(console_ns.payload)

    message_id = args.message_id

    message = session.scalar(select(Message).where(Message.id == message_id, Message.app_id == app_model.id).limit(1))

    if not message:
        raise NotFound("Message Not Exists.")

    feedback = message.admin_feedback_with_session(session=session)

    if not args.rating and feedback:
        session.delete(feedback)
    elif args.rating and feedback:
        feedback.rating = FeedbackRating(args.rating)
        feedback.content = args.content
    elif not args.rating and not feedback:
        raise ValueError("rating cannot be None when feedback not exists")
    else:
        rating_value = args.rating
        if rating_value is None:
            raise ValueError("rating is required to create feedback")
        feedback = MessageFeedback(
            app_id=app_model.id,
            conversation_id=message.conversation_id,
            message_id=message.id,
            rating=FeedbackRating(rating_value),
            content=args.content,
            from_source=FeedbackFromSource.ADMIN,
            from_account_id=current_user.id,
        )
        session.add(feedback)

    session.commit()

    return SimpleResultResponse(result="success").model_dump(mode="json")

View on GitHub (pinned to ef8544b173)

Solutions

  1. If you want to rate, include rating='like' or rating='dislike' in the payload.
  2. If you want to clear feedback, only call this when a feedback record already exists (track prior state client-side).
  3. Treat the absence of existing feedback as a no-op on the client rather than sending a delete.

Example fix

// before
POST /feedbacks  { "message_id": "..." }
// after
POST /feedbacks  { "message_id": "...", "rating": "like" }
Defensive patterns

Strategy: validation

Validate before calling

// Only send delete (no rating) when a feedback record exists client-side
function buildFeedbackPayload(message, currentRating) {
  if (!message.rating && !currentRating) {
    // nothing to clear; do not call
    return null;
  }
  return { message_id: message.id, rating: currentRating };
}

Try / catch

try {
  await submitFeedback(appId, payload);
} catch (e) {
  if (e.code === 'invalid_param' && /rating cannot be none/i.test(e.message)) {
    // no existing feedback to delete; treat as no-op
  } else throw e;
}

Prevention

When it happens

Trigger: POST /console/api/apps/<app_id>/feedbacks with no rating field (or rating=null) for a message that has no prior feedback record.

Common situations: Client sending a 'clear feedback' request for a message the user never rated; toggling a like/dislike off before it was ever set; UI bug omitting rating on first submit.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/710e7786b5d46d0b. Report an issue: GitHub.