title: Hyperledger composer: calling a query within a transaction that updated an asset returns old results
body: <p>I have a problem with a very simple Hyperledger Composer applicationnamespace com.softwaremill.drivernetwork</p>
  
  <pre><code>participant Driver identified by licenseId {
    o String licenseId
    o String firstName
    o String lastName
    o Boolean licenseValid default =true
  }
  
  enum LaweEnforcerType {
    o POLICE
    o CUSTOMS
    o BORDER_GUARDS
  }
  
  participant LawEnforcer identified by lawEnforcerId {
    o String lawEnforcerId
    o LaweEnforcerType lawEnforcerType
  }
  
  participant Court identified by courtId {
    o String courtId
    o String description
  }
  
  enum FineState {
    o ISSUED
    o REJECTED
    o ACCEPTED
  }
  
  asset Fine identified by fineId {
    o String fineId
    o Integer penaltyPoints
    o DateTime date
    o FineState fineState default ="ISSUED"
    --&gt; Driver driver
    --&gt; LawEnforcer lawEnforcer
  }
  
  asset CourtCase identified by caseId {
    o String caseId
    --&gt; Court court optional
    --&gt; Fine fine
  }
  
  transaction AcceptedFine {
    --&gt; Fine fine
  }
  
  transaction RejectedFine {
    --&gt; Fine fine
  }
  </code></pre>
  
  <p>LawEnforcer can issue a Fine. The Fine can be either Accepted or Rejected (then it goes to Court) by the driver.</p>
  
  <p>What I am trying to do is to automatically invalidate the driver's license if the sum of all his accepted <code>penaltyPoints</code> on Fines exceeds 20 points.</p>
  
  <p>So I have created a transaction processor</p>
  
  <pre><code>/**
   * Accept fine
   * @param {com.softwaremill.drivernetwork.AcceptedFine} acceptedFine
   * @transaction
   */
  async function acceptedFine(acceptedFine) {
      console.log(`Accepting fine ${acceptedFine}`);
  
      const fineRegistry = await     getAssetRegistry('com.softwaremill.drivernetwork.Fine');
  
      acceptedFine.fine.fineState = 'ACCEPTED';
      await fineRegistry.update(acceptedFine.fine); // [1]
  
      const allFines = await query('selectAcceptedFinesByDriver', 
      {driver: `resource:com.softwaremill.drivernetwork.Driver#${acceptedFine.fine.driver.licenseId}`}); // [2]
  
      if (allFines.reduce((acc, val) =&gt; {return acc + val.penaltyPoints;}, 0) &gt; 20) {
          console.log('Driver excceded 20 points, blocking license');
  
          const driverRegistry = await getParticipantRegistry('com.softwaremill.drivernetwork.Driver');
  
          acceptedFine.fine.driver.licenseValid = false;
  
          await driverRegistry.update(acceptedFine.fine.driver);
      }
  }
  </code></pre>
  
  <p>And the query code</p>
  
  <pre><code>query selectAcceptedFinesByDriver {
    description: "Select all accepted fines for a given driver"
    statement:
      SELECT com.softwaremill.drivernetwork.Fine
        WHERE (driver == _$driver AND fineState == "ACCEPTED")
  }
  </code></pre>
  
  <p>Now the code should set the Fine state to <code>ACCEPTED</code> at <code>[1]</code>. This works - after the transaction is processed I am able to see the property changed.</p>
  
  <p>But the problem is that at <code>[2]</code> when the query is executed the Fine that just got updated at <code>[1]</code> has still status <code>ISSUED</code> (I've removed the right part of where in the query to debug it).</p>
  
  <p>What am I missing here? Is the shape of the blockchain someone frozen for the transaction? What is going on?</p>