'Unexpected state:' calculation error

After updating from 5.2.6 to 5.2.7 last week we are seeing the following error in the server log,

Unexpected state: calculation depends on field ‘qty_qc’ from record without pk: Record[DATA:null] COLUMS: exp_po_add2_id,po_line,po_num,po_cnn,certificate_complete,qty_qc,is_release_item,um_qc,qty_difference,rollbackChanges,save,getPKs,setFoundset,deleteRecord,getChangedData,setException,getFoundset,getException,isEditing,
java.lang.IllegalStateException

and calculations are not updated on the form, this happens after adding a record to the table below, when I look in the table the primary key is not empty. The database we use is ms-sql 2008 and the sequence type is db identity.

[attachment=0]calc.png[/attachment]

when the smartclient is restarted the calculations are executed correctly. This only happens with version 5.2.7, developer and smartclient.

Another one,

No DbIdent for this row: Row(db:/servoy/tp_file_entity)[DATA:tp_file_entity_id=DbIdentValue29465650,entity_type=29,entity_id=432,file_id=3898,enclose=null, CALCULATIONS: {foundcount=java.lang.Object@1d80f4b, file_download_link=java.lang.Object@1d80f4b, icon=java.lang.Object@1d80f4b, descript=java.lang.Object@1d80f4b, image=java.lang.Object@1d80f4b, createddate=java.lang.Object@1d80f4b, file_name=java.lang.Object@1d80f4b, bgcolor=java.lang.Object@1d80f4b, toggle_image=media:///icon_pdf.gif}]

[attachment=0]table.png[/attachment]

After adding a row to a small table…

dont you have a full stacktrace for this in the log?

I discovered that the problem does not occur with version 5.2.7 i1 also version prior to 5.2.7 do not have this problem.

Has this been resolved? I seem to be getting the same error using 5.2.7 with Sybase. It is intermittent, and I’m seeing it on the server, not developer. The table has dbident PK. All the keys seem be OK.

Here’s the error:

ERROR - Debug                      - Unexpected state: calculation depends on field 'shortlist_memo' from record without pk: Record[DATA:null]  COLUMS: c6pkey,user_uid,table_name,table_counter,pkey_value,shortlist_memo,rollbackChanges,save,getPKs,setFoundset,deleteRecord,getChangedData,setException,getFoundset,getException,isEditing,
java.lang.IllegalStateException
	at com.servoy.j2db.scripting.UsedDataProviderTracker.usedFromRecord(UsedDataProviderTracker.java:170)
	at com.servoy.j2db.scripting.UsedDataProviderTracker.usedName(UsedDataProviderTracker.java:89)
	at com.servoy.j2db.scripting.RecordingScriptable.get(RecordingScriptable.java:123)
	at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1641)
	at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1429)
	at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1418)
	at org.mozilla.javascript.gen.c221._c0(c6shortmemo:14)
	at org.mozilla.javascript.gen.c221.call(c6shortmemo)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3135)
	at org.mozilla.javascript.gen.c221.call(c6shortmemo)
	at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:476)
	at com.servoy.j2db.scripting.TableScope.getCalculationValue(TableScope.java:191)
	at com.servoy.j2db.scripting.TableScope.getCalculationValue(TableScope.java:214)
	at com.servoy.j2db.dataprocessing.FoundSet.getCalculationValue(FoundSet.java:2567)
	at com.servoy.j2db.dataprocessing.Record.getValue(Record.java:181)
	at com.servoy.j2db.smart.dataui.CellAdapter$5.run(CellAdapter.java:758)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Here’s the code:

function c6shortmemo()
{
	var lofsrecent = databaseManager.getFoundSet(globals.gcservername,'c6userrecent');
	lofsrecent.addFoundSetFilterParam('user_uid','=',globals.gcuser_uid);
	lofsrecent.addFoundSetFilterParam('table_name','=','C6CLIENT');
	lofsrecent.addFoundSetFilterParam('pkey_value','=',c6pkey,'pkey_filter');
	lofsrecent.loadAllRecords()
	var lorecentrec = lofsrecent.getSelectedRecord()
	if (lorecentrec)
	{	
		return lorecentrec.shortlist_memo
	}
	else
	{	
		return null
	}
}

Michael,

Can you reproduce this consistently?

Rob

Unfortunatley no - it is intermittent. Using the same records, sometimes it happens, and sometimes not. I can find no pattern. BTW - there is nothing in the server log regarding it.

M.S.

Michael,

This exception is just logging an unexpected situation, it is not bailing out some code.
I made a change for 5.2.9 that will probably get rid of it.

Rob

Problem is the calculation doesn’t return a value. In this case, the calc field is the data provider for a tableview field. After the calc is run, it should refresh the display. Sometimes it does and sometimes it does not.

Michael,

This could be caused by a race condition in the calculation.
Servoy always first gets the pks from the db and when the data is requested, a new query is done.

Could it be that the record is being deleted when the calc is running?
The first pk load query may still see the record in the db, but the load-data query does not see the record anymore.
In that case this issue could occur.

Can you add a debug statement to your calculation so we can conform this?

function c6shortmemo()
{
   var lofsrecent = databaseManager.getFoundSet(globals.gcservername,'c6userrecent');
   lofsrecent.addFoundSetFilterParam('user_uid','=',globals.gcuser_uid);
   lofsrecent.addFoundSetFilterParam('table_name','=','C6CLIENT');
   lofsrecent.addFoundSetFilterParam('pkey_value','=',c6pkey,'pkey_filter');
   lofsrecent.loadAllRecords()
   var sizeBefore = lofsrecent.getSize() // DEBUG
   var lorecentrec = lofsrecent.getSelectedRecord()
   if (lorecentrec)
   { 
      var sizeAfter = lofsrecent.getSize() // DEBUG
      if (sizeBefore != sizeAfter) // DEBUG
     { // DEBUG
          application.output("DEBUG: foudset size changed from "+sizeBefore+" to "+sizeAfter+" rec="+lorecentrec+" fs="+lofsrecent); // DEBUG
     } // DEBUG
      return lorecentrec.shortlist_memo
   }
   else
   {   
      return null
   }
}

Rob

PS, this is rather an expensive calculation.
A relation with variable arguments could be a better solution, a feature request for that in a future version may help.

Rob

I added the debug code, but nothing appears in the server log when the error occurs in the java console.

you could try:

application.output(‘my very important msg’,LOGGINGLEVEL.ERROR);

so that it really is reported as an error, but if still nothing is reported then it isn’t want we think happens maybe an extra line in there that test the variable shortlist_memo for null or something could be done.

We are getting these in 5.2.17 :

ERROR - Debug - Unexpected state: calculation ‘glb_output_detail_to_crm_department_output’ depends on column ‘glb_output_detail_to_crm_department_output’ from record without pk: FindRecord[COLUMS: {owner_id,log_creation_user,log_creation_dt,log_modification_user,log_modification_dt,quantity,unit_price,unit_price_incl_vat,price,price_incl_vat,description,fin_vat_code_id,glb_output_detail_id,crm_department_output_id,output_detail_type,sequence_number,excluded_from_total_amount,percentage,percentage_base,currency_unit_price,currency_price,currency_unit_price_incl_vat,currency_price_incl_vat,sequence_number_detail_type,glb_unit_id,origin_type,origin_id,due_date,start_date,cost_unit_price,percentage_currency_base,total_quantity,} DATA:{origin_id=13052}, RELATED: {glb_output_detail_to_crm_department_output=FoundSet[Table:crm_department_output,Size: 1,Relation: glb_output_detail_to_crm_department_output,CachedRecords: 1,SELECTED INDEX: 0]}]

What to do ?

Regards,

that somehow a calculation that is triggered when you are in find mode.
So the calculation wants to generate a value but it can’t because where it wants to get data from is a findstate
This shouldn’t be really a problem, not sure how this can really happen. Is there somewhere a parent record that is not in find mode that has a calculation and that one has a relation (related foundset) that is somehow in find mode?
and that calculation uses that relation to show something?