Last Comment Bug 99215 - Attachments have no midair collision protection
: Attachments have no midair collision protection
Status: RESOLVED FIXED
:
Product: Bugzilla
Classification: Server Software
Component: Attachments & Requests (show other bugs)
: 2.15
: All All
: -- normal with 1 vote (vote)
: Bugzilla 3.2
Assigned To: Frédéric Buclin
: default-qa
Mentors:
: 212180 233393 365271 391405 (view as bug list)
Depends on:
Blocks: 401007 423346
  Show dependency treegraph
 
Reported: 2001-09-10 17:14 PDT by David Baron :dbaron: ⌚️UTC-7 (review requests must explain patch)
Modified: 2014-04-25 15:16 PDT (History)
13 users (show)
justdave: approval+
See Also:
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
patch, v1 (14.46 KB, patch)
2007-09-09 07:20 PDT, Frédéric Buclin
mkanat: review-
Details | Diff | Review
patch, v2 (14.39 KB, patch)
2007-09-23 15:03 PDT, Frédéric Buclin
mkanat: review+
justdave: review+
Details | Diff | Review
add missing index when upgrading, v1 (773 bytes, patch)
2007-11-29 14:48 PST, Frédéric Buclin
mkanat: review+
Details | Diff | Review

Description David Baron :dbaron: ⌚️UTC-7 (review requests must explain patch) 2001-09-10 17:14:26 PDT
(I'm reporting this in whatever version of bugzilla http://bugzilla.mozilla.org/
runs as of 10 minutes ago.)

Changes to attachment status have no midair collision detection.  This causes
problems like the one seen in
http://bugzilla.mozilla.org/show_activity.cgi?id=93164 at 2001-09-10 17:02.

Steps to reproduce:
 * Click the "Edit" link for one attachment in one browser
 * do the same in another browser
 * check "has review" in the first, and submit
 * check "has super-review" in the second, and submit

Result:
 * the attachment no longer has review

Expected result alternative #1:
 * midair collision report

Expected result alternative #2:
 * the attachment has both review and super-review

I prefer #1 because of the possibility of withdrawing review for a bug (or the
possibility of one person marking an attachment obsolete as another is
reviewing) -- if it were not possible to unset the states once they were set
then #2 would be preferable.
Comment 1 Matthew Tuck [:CodeMachine] 2001-09-10 22:03:07 PDT
I'll agree here, but do we want midair protection over the whole bug?  Two
create attachments currently clash ... I think a change to one attachment should
clash with a change to another attachment, because it's all the same bug.
Comment 2 Myk Melez [:myk] [@mykmelez] 2001-09-11 11:45:42 PDT
The purpose of midair protection is to prevent one user's changes from
overwriting another's, not to prevent two people from changing the same bug at
once.  Simultaneous changes to two different attachments at the same time do not
have the potential to collide in midair and thus do not need midair protection.
Comment 3 Matthew Tuck [:CodeMachine] 2001-09-11 18:46:36 PDT
AIUI the purpose of midair is to prevent a second person making a change
unnecessary after the first change.  There could be situations where this could
occur on separate attachments or between an attachment and the bug.

If what you say was true, we would have attempted to make midair collisions not
occur when different fields on the same bug were touched.
Comment 4 Bradley Baetz (:bbaetz) 2002-01-17 01:59:43 PST
(side note)It is sometimes useful not to clash, eg someone adding themselves to
the cc list shouldn't clash with a summary change.

If there are no fields in common (or the fields are lits, like
cc/dependancy/etc), I'd like a "keep going" option on the midair screen. Thats a
separate bug, though
Comment 5 Gervase Markham [:gerv] 2002-02-03 01:28:31 PST
Nominating for 2.16 blocker - this really isn't ideal.

Gerv
Comment 6 Dave Miller [:justdave] (justdave@bugzilla.org) 2002-02-11 21:33:39 PST
Let me get this straight...  we want midair collisions to occur when two people
edit the same attachment, but not when people edit different attachments or when
one person edits the bug while someone else is editing an attachment?

So basically, we need a timestamp field for last modified on each attachment
record as well?
Comment 7 Matthew Tuck [:CodeMachine] 2002-02-11 21:38:48 PST
We should do the quick fix and just update the bug's timestamp.  Luckily, this
is also the right fix.
Comment 8 Gervase Markham [:gerv] 2002-02-21 13:34:01 PST
MattyT: are you able to produce a patch to that effect?

Gerv
Comment 9 Bradley Baetz (:bbaetz) 2002-02-21 13:51:01 PST
Well, commenting should check the bug while attachment statues should check the
attachment. However, in practice can't we just check the bug? An extra midair
when editing a different attachment won't hurt, and is probably sufficiently
rare that its not worth adding an extra tiemstamp field to the attachment table.

The obsolete stuff from creating an attachment is sort of protected, because it
errors out if one of the attachments is already obsolete. (Although of course it
doesn't do any locking, so its not really safe. Setting isobsolete on an
attachment which is already obsolete won't hurt, though)

Should creating two different attachments midair?

Theres attachments.creation_ts - is that really the last-modified time? It looks
that way, and thats what the header in Attachment.pm::List says...
Comment 10 Matthew Tuck [:CodeMachine] 2002-02-21 22:04:30 PST
Creating two attachments should definitely midair - all duplicate actions should
midair because they can be mistakes.
Comment 11 Bradley Baetz (:bbaetz) 2002-03-16 03:11:14 PST
myk: see my laste paragraph in comment 9. If what we're doing is correct, then I
can just use that.

Do note that going back after having done "edit attachment as comment" in
mozilla will lose your comments. I'm not sure if there is a mozilla bug filed on
that.
Comment 12 Myk Melez [:myk] [@mykmelez] 2002-03-18 14:31:07 PST
Yes, attachments.creation_ts is indeed to the last modified time.
Comment 13 Bradley Baetz (:bbaetz) 2002-03-30 17:35:54 PST
Would be very nice, but no patch, not a stopper, and probably a fair bit of work
to check all the cases.

->2.18
Comment 14 Gervase Markham [:gerv] 2003-12-09 07:17:33 PST
Definitely not a blocker.

Gerv
Comment 15 Dave Miller [:justdave] (justdave@bugzilla.org) 2004-03-19 21:04:50 PST
All 2.18 bugs that haven't been touched in over 60 days and aren't flagged as
blockers are getting pushed out to 2.20
Comment 16 Max Kanat-Alexander 2005-03-05 04:47:28 PST
This bug has not been touched by its owner in over six months, even though it is
targeted to 2.20, for which the freeze is 10 days away. Unsetting the target
milestone, on the assumption that nobody is actually working on it or has any
plans to soon.

If you are the owner, and you plan to work on the bug, please give it a real
target milestone. If you are the owner, and you do *not* plan to work on it,
please reassign it to nobody@bugzilla.org or a .bugs component owner. If you are
*anybody*, and you get this comment, and *you* plan to work on the bug, please
reassign it to yourself if you have the ability.
Comment 17 Frédéric Buclin 2005-03-14 17:00:57 PST
*** Bug 212180 has been marked as a duplicate of this bug. ***
Comment 18 Frédéric Buclin 2005-03-14 17:19:40 PST
*** Bug 233393 has been marked as a duplicate of this bug. ***
Comment 19 Frédéric Buclin 2005-06-28 05:18:02 PDT
(In reply to comment #12)
> Yes, attachments.creation_ts is indeed to the last modified time.

Oh really? Actually, creation_ts is the creation date of the attachment and an
additional field similar to delta_ts is required in the attachments table in
order to fix this bug correctly.

It does not make sense to midair when the bug or another attachment is being
modified at the same time. And marking an attachment as obsolete when submitting
a new attachment should update the delta_ts-like field of the obsoleted
attachment in order to correctly reflect the change.

We are frozen and 2.20rc1 should be released this week. So pushing it to 2.22,
unfortunately.
Comment 20 Frédéric Buclin 2005-10-25 17:05:06 PDT
I won't have time to play with it before the 2.22 freeze
Comment 21 Frédéric Buclin 2006-12-28 14:58:24 PST
*** Bug 365271 has been marked as a duplicate of this bug. ***
Comment 22 Dave Miller [:justdave] (justdave@bugzilla.org) 2006-12-28 20:24:25 PST
Attachments actually have working independent creation and modification dates now (they didn't the last time there was major discussion on this bug) so this should actually be easily doable now.  Too much change to shoehorn into 3.0 though, we're frozen.
Comment 23 Frédéric Buclin 2007-08-08 11:49:50 PDT
*** Bug 391405 has been marked as a duplicate of this bug. ***
Comment 24 Nelson Bolyard (seldom reads bugmail) 2007-08-08 12:11:52 PDT
Here's another recent example.
I received a review request on a patch.  So I went to the bug, clicked
on the "details" link for the patch, spent about 20 minutes writing a 
review and setting the review flag on the attachment details page, and 
then I clicked submit.

While I had been writing that review, the author of the patch found a bug
in the patch I was reviewing, and submitted another patch, and marked the
patch I was reviewing obsolete, which cancelled the review request to me
as well as to another reviewer.  But I did not know any of that had happened.

So, when I submitted my review, submitting the contents of the details
page, I effectively undid his recent changes.  My submission removed the
obsolete flag from the patch I reviewed, and it restored the review request
to the other reviewer for the patch I had reviewed.  I received no warning
from the b.m.o web server about any of this.  

I learned about the collision when I received the email from b.m.o, telling
me of the changes I had made.  There I saw that it appeared at I had 
unobsoleted the patch, and that I had requested that another reviewer 
also review that patch. 
Comment 25 Frédéric Buclin 2007-09-09 07:20:46 PDT
Created attachment 280247 [details] [diff] [review]
patch, v1
Comment 26 Frédéric Buclin 2007-09-17 05:04:44 PDT
Comment on attachment 280247 [details] [diff] [review]
patch, v1

Max, could you look at the DB and upgrade parts of the patch?
Myk, could you look at the attachment part?
Comment 27 Max Kanat-Alexander 2007-09-17 16:34:59 PDT
Comment on attachment 280247 [details] [diff] [review]
patch, v1

>         INDEXES => [
>             attachments_bug_id_idx => ['bug_id'],
>             attachments_creation_ts_idx => ['creation_ts'],
>+            attachments_modif_time_idx => ['modification_time'],

  Index names *must* contain the full name of the first field.

>Index: Bugzilla/Install/DB.pm
> [snip]
>+sub _fix_attachment_modification_date {
>+    my $dbh = Bugzilla->dbh;
>+    $dbh->bz_add_column('attachments', 'modification_time', {TYPE => 'DATETIME'});
>+
>+    my $attachments_with_no_modif_time =
>+      $dbh->selectcol_arrayref('SELECT attach_id FROM attachments
>+                                WHERE modification_time IS NULL');

  Just check if the column exists, and then add it and do these things if it doesn't exist.

>+    print "Setting the modification time for attachments having none...\n";
>+    foreach my $attach_id (@$attachments_with_no_modif_time) {
>+        my $time = $dbh->selectrow_array($sth_select, undef, $attach_id);
>+        if ($time) {
>+            $sth_update->execute($time, $attach_id);
>+        }
>+        else {
>+            # The attachment has never been edited. Use the creation time.
>+            $sth_sync->execute($attach_id);
>+        }

  Wait, if this is set to creation_ts when the attachment hasn't been modified, then why is modified_time allowed to be NULL? Either it should be NOT NULL or NULL should represent "never modified". (I prefer the second, but if the first makes sense, that's fine too. You could always put that logic into Attachment.pm instead of into the DB, though.)
Comment 28 Frédéric Buclin 2007-09-23 15:03:35 PDT
Created attachment 282039 [details] [diff] [review]
patch, v2

mkanat: DB + upgrade parts; myk: attachment part.
Comment 29 Max Kanat-Alexander 2007-09-23 15:06:51 PDT
Comment on attachment 282039 [details] [diff] [review]
patch, v2

Yeah, the DB part looks fine.

At the bottom of the upgrade code, you might want to make that foreach loop a bit clearer, for people who aren't perl gurus.
Comment 30 Dave Miller [:justdave] (justdave@bugzilla.org) 2007-11-28 16:42:12 PST
Comment on attachment 282039 [details] [diff] [review]
patch, v2

ok, this works as designed on the trunk in my testing. My only concern is the text "This will cause all of the above changes to be overwritten" next to the Submit anyway button, but we have the same text on the bug midair page, too, and I'm sure there's another bug on that somewhere (because it's not always accurate)
Comment 31 Dave Miller [:justdave] (justdave@bugzilla.org) 2007-11-28 16:45:14 PST
They want this on b.m.o, but we're not upgrading to tip yet, which means we get to backport this patch.  It *almost* applies cleanly on the 3.0 branch, and the one conflict was painless to apply manually, however there must be API changes somewhere between 3.0 and trunk that affect this because it doesn't work on the branch (no errors anywhere, but the midair is never triggered).

For the record, I don't want a 3.0 backport committed to CVS, it does schema changes, and I don't want schema changes on the branch unless necessary for a security issue.
Comment 32 Frédéric Buclin 2007-11-29 11:49:49 PST
Checking in attachment.cgi;
/cvsroot/mozilla/webtools/bugzilla/attachment.cgi,v  <--  attachment.cgi
new revision: 1.137; previous revision: 1.136
done
Checking in process_bug.cgi;
/cvsroot/mozilla/webtools/bugzilla/process_bug.cgi,v  <--  process_bug.cgi
new revision: 1.394; previous revision: 1.393
done
Checking in Bugzilla/Attachment.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Attachment.pm,v  <--  Attachment.pm
new revision: 1.51; previous revision: 1.50
done
Checking in Bugzilla/Bug.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Bug.pm,v  <--  Bug.pm
new revision: 1.218; previous revision: 1.217
done
Checking in Bugzilla/DB/Schema.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/DB/Schema.pm,v  <--  Schema.pm
new revision: 1.90; previous revision: 1.89
done
Checking in Bugzilla/Install/DB.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Install/DB.pm,v  <--  DB.pm
new revision: 1.43; previous revision: 1.42
done
Checking in template/en/default/filterexceptions.pl;
/cvsroot/mozilla/webtools/bugzilla/template/en/default/filterexceptions.pl,v  <--  filterexceptions.pl
new revision: 1.109; previous revision: 1.108
done
Checking in template/en/default/attachment/edit.html.tmpl;
/cvsroot/mozilla/webtools/bugzilla/template/en/default/attachment/edit.html.tmpl,v  <--  edit.html.tmpl
new revision: 1.49; previous revision: 1.48
done
RCS file: /cvsroot/mozilla/webtools/bugzilla/template/en/default/attachment/midair.html.tmpl,v
done
Checking in template/en/default/attachment/midair.html.tmpl;
/cvsroot/mozilla/webtools/bugzilla/template/en/default/attachment/midair.html.tmpl,v  <--  midair.html.tmpl
initial revision: 1.1
done
Comment 33 Frédéric Buclin 2007-11-29 14:48:31 PST
Created attachment 290760 [details] [diff] [review]
add missing index when upgrading, v1

The DB index is omitted when upgrading, making Tinderbox to fail. Oops!
Comment 34 Frédéric Buclin 2007-12-01 14:21:03 PST
mkanat, could you review the 2nd fix about the missing index?
Comment 35 Max Kanat-Alexander 2007-12-01 17:47:19 PST
Comment on attachment 290760 [details] [diff] [review]
add missing index when upgrading, v1

Looks good to me.
Comment 36 Frédéric Buclin 2007-12-02 07:22:25 PST
Checking in Bugzilla/Install/DB.pm;
/cvsroot/mozilla/webtools/bugzilla/Bugzilla/Install/DB.pm,v  <--  DB.pm
new revision: 1.44; previous revision: 1.43
done
Comment 37 Max Kanat-Alexander 2008-06-29 16:48:33 PDT
Added to the Bugzilla 3.2 release notes in bug 432331.

Note You need to log in before you can comment on or make changes to this bug.