Defect #9685

Adding multiple times the same related issue relation is possible

Added by Etienne Massip over 5 years ago. Updated over 5 years ago.

Status:ClosedStart date:2011-11-29
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Issues
Target version:1.4.0
Resolution:Fixed Affected version:1.2.2

Description

See #4911, I added relation to #7445 twice in a row with Firefox (unstable) just pressing Enter key, maybe longer than normal.

add_unique_index_in_issue_relations.patch Magnifier (1013 Bytes) Etienne Massip, 2011-12-01 20:54

Associated revisions

Revision 8041
Added by Etienne Massip over 5 years ago

Enforced unicity of relations between 2 issues with a database index (#9685).

History

#1 Updated by Etienne Massip over 5 years ago

  • Subject changed from Adding multiple times the same related issue is possible to Adding multiple times the same related issue relation is possible

As explained in RoR documentation (both 2.3.x and 3.x, this excerpt is from 3.x'):

Concurrency and integrity

Using this validation method in conjunction with ActiveRecord::Base#save does not guarantee the absence of duplicate record insertions, because uniqueness checks on the application level are inherently prone to race conditions.
(...)
This could even happen if you use transactions with the ‘serializable’ isolation level. The best way to work around this problem is to add a unique index to the database table using (...)#add_index.

(...)
The bundled ActiveRecord::ConnectionAdapters distinguish unique index constraint errors from other types of database errors by throwing an ActiveRecord::RecordNotUnique exception. For other adapters you will have to parse the (database-specific) exception message to detect such a case.

A simple migration creating an unique index on to and from issue_relation columns should do the job.

#2 Updated by Etienne Massip over 5 years ago

Migration patch attached.

#3 Updated by Etienne Massip over 5 years ago

  • Target version changed from Candidate for next minor release to Candidate for next major release

Ok, since there is a migration, moving to major.

#4 Updated by Jean-Philippe Lang over 5 years ago

  • Target version changed from Candidate for next major release to 1.4.0

#5 Updated by Etienne Massip over 5 years ago

  • Status changed from Confirmed to Resolved
  • Resolution set to Fixed

Migration committed with r8041.

#6 Updated by Jean-Philippe Lang over 5 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF