Opened 9 years ago

Closed 9 years ago

#1945 closed defect (fixed)

It's not possible to create an item and add it to an item list in the same transaction

Reported by: Nicklas Nordborg Owned by: everyone
Priority: blocker Milestone: BASE 3.5.1
Component: core Version:
Keywords: Cc:

Description

This is not possible to reproduce in the web gui, but requires a plug-in or extensions. This was discovered in the "Reggie" extensions when registering RNA and at the same time trying to add them to the "Flagged RNA" item list.

To reproduce:

  1. Start transaction
  2. Create a new item
  3. Load an existing item list (let it be empty to make things easier)
  4. Add the item to the item list
  5. Commit the transaction

Everything should complete without errors. Check the item list in the web gui. It should claim a size of "1" but when listing the members it is empty.

Further investigations show that 0 has been added as member to list. This happens because the new item starts out with id=0 and doesn't get a real id until the commit in step 5. When the item is added to the list in step 4, 0 is copied to the list and the size is incremented. But since there is no item that has id=0 the list appears to have no members.

In BASE 3.4 the linking of members was mapped as relations managed by Hibernate and Hibernate ensured that values were inserted in the correct order into the database. The change in BASE 3.5 (#1325) that enables support for other item types in items lists means that we can't use Hibernate to manage the relations. So, our code needs to be "smarter" and detect this kind of issue.

There are other parts of the API that doesn't allow unsaved items to be used and throws an exception. But it is not a good solution in this case, since there are existing code that expects things to work more or less as before.

We need to fix the item list code so that it put unsaved items on hold and then hooks into the commit phase to make sure that the correct id is inserted into the list.

Change History (5)

comment:1 by Nicklas Nordborg, 9 years ago

(In [6882]) References #1945: It's not possible to create an item and add it to an item list in the same transaction

Added test case that try to create a new item and add it to an item list in the same transaction. While this step is "successful" it will trigger the bug and listing the members will detect a mismatch between the expected number of members, the actual number of members and the "size" of the list.

comment:2 by Nicklas Nordborg, 9 years ago

(In [6883]) References #1945: It's not possible to create an item and add it to an item list in the same transaction

This should fix the problem for the add and remove methods working with individual Listable items. We also need to fix the add, union, and other methods that work with other item lists.

comment:3 by Nicklas Nordborg, 9 years ago

(In [6884]) References #1945: It's not possible to create an item and add it to an item list in the same transaction

This should fix the problem for the rest of the methods that work with unions, etc. of multiple lists.

comment:4 by Nicklas Nordborg, 9 years ago

(In [6885]) References #1945: It's not possible to create an item and add it to an item list in the same transaction

Added update script for fixing item lists that has got a '0' member. The fix will simply remove the '0' and decrease the size with 1. Items that was missed when added to the list can't be recovered and must be added manually.

comment:5 by Nicklas Nordborg, 9 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.