Skip to content

Bug 1877201 - Fix for a wrong comment_id returned after POST to bug/{bug_id}/comment - #2742

Open
ksy36 wants to merge 1 commit into
mozilla:masterfrom
ksy36:comment_id_fix
Open

Bug 1877201 - Fix for a wrong comment_id returned after POST to bug/{bug_id}/comment#2742
ksy36 wants to merge 1 commit into
mozilla:masterfrom
ksy36:comment_id_fix

Conversation

@ksy36

@ksy36 ksy36 commented Sep 11, 2026

Copy link
Copy Markdown

I came across an issue where after posting comments to bug/{bug_id}/comment, the endpoint returns wrong comment id.

For example, for https://bugzilla.mozilla.org/show_bug.cgi?id=2068734, it returned 4120899, 4120900, 4120901 for the last 3 comments, while the actual ids are 18336000, 18336001 and 18336002.

It's currently passing comment_id to bz_last_key to get the id of just inserted comment

my $new_comment_id = $dbh->bz_last_key('longdescs', 'comment_id');

https://github.com/mozilla/bmo/blob/master/Bugzilla/WebService/Bug.pm#L1332-L1342

but on MySQL these parameters appears to be unused, it just selects last inserted id, which in this case is not a comment id, but auto incremented id from another table

sub bz_last_key {
  my ($self) = @_;

  my ($last_insert_id) = $self->selectrow_array('SELECT LAST_INSERT_ID()');

  return $last_insert_id;
}

https://github.com/mozilla/bmo/blob/master/Bugzilla/DB/Mysql.pm#L95-L101

I couldn't reproduce this locally though, so it might be something that's happening only on production.

@ksy36

ksy36 commented Sep 11, 2026

Copy link
Copy Markdown
Author

@dklawren, could you please r?

@dklawren
dklawren requested review from dklawren and a balanced review from Copilot September 11, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation avoids unrelated auto-increment values and includes appropriate regression coverage.

Pull request overview

Fixes REST comment creation to return the inserted comment’s actual ID.

Changes:

  • Uses the created comment object’s ID instead of connection-wide LAST_INSERT_ID().
  • Adds regression coverage validating the returned ID.
File summaries
File Description
Bugzilla/WebService/Bug.pm Returns the inserted comment object’s ID.
qa/t/rest_bug_add_comment.t Verifies the response references the newest comment.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dklawren dklawren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM r=dkl

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 this pull request may close these issues.

3 participants