Uploaded image for project: 'DSpace'
  1. DSpace
  2. DS-4434

Context "commit()" invalidates a Context (temporarily) until next change is made

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.3, 7.0
    • Fix Version/s: 7.0
    • Component/s: DSpace API
    • Labels:
      None
    • Attachments:
      0
    • Comments:
      2
    • Documentation Status:
      Not Required

      Description

      During the upgrade to JDK11 (DS-4380), I encountered some odd behaviors (while updating tests) with how the "org.dspace.core.Context" class behaves immediately after a "commit()" occurs.

      After some deeper digging in the Context & HibernateDBConnection code, I realized that the "Context.commit()" method was temporarily invalidating the Context object (i.e. "context.isValid()" would return false immediately after a commit()...even though the Context object was still usable). 

      I also noticed that the Context.commit() method had no tests to prove that it behaved as expected.  I was immediately able to prove the unexpected behavior via a new test.  Namely, on "master", a test of this nature will cause a failure:

      1. First, make changes to an object within a valid Context.
      2. Call "context.commit()"
      3. Immediately call "context.isValid()". You'd expect it to return "true" (as a commit() should not invalidate a Context). However, it will return false.
      4. Make other changes on that same Context (without calling a commit())
      5. Call "context.isValid()" again. This time, it will return "true" (as making more changes in the Context will create a new Hibernate Transaction, thus making the previously-invalid Context "valid" again)

      Based on the description of the "Context.commit()" method, this behavior seems inappropriate. It also implies a failure of the "Context.isValid()" method to actually return whether a Context is "valid" and can continue to be used. Even though it immediately returns "false" the Context can continue to be used nonetheless.

      I've prepared a PR to refactor/correct the behavior of these Context methods based on new Tests (both for "org.dspace.core.Context" and "org.dspace.core.HibernateDBConnection"). I'll post that PR shortly.

        Attachments

          Activity

            People

            Assignee:
            tdonohue Tim Donohue
            Reporter:
            tdonohue Tim Donohue
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: