Question
· Nov 14, 2016

Unexpected ROLLFAIL error in an object %Save() call

In writing some code on:

Cache for Windows (x86-64) 2015.1 (Build 429U) Fri Feb 13 2015 14:37:23 EST

I noticed an unexpected "ROLLFAIL" error when a Unique Index fail was generated in a %Save() call.

The object SHOULD fail to save, since the Unique criteria is not met, but I didn't expect to see a ROLLFAIL error as the "Last Error".

When running the following class code:

Class BUG.Test Extends %Persistent
{

Property Field1 As %String;

Property Field2 As %String;

Index idx1 On Field1 [ Unique ];

ClassMethod Test()
{
    kill ^BUG.TestD
    kill ^BUG.TestI

    ; Should work fine
    set record1 = ##class(BUG.Test).%New()
    set record1.Field1 = "Bosco"
    set record1.Field2 = "Jones"
    set sc = record1.%Save()
    if $$$ISERR(sc) {
        do $System.OBJ.DisplayError(sc)
    } else {
        write !,"Save OK ID: "_record1.%Id()
    }

    ; Should work fine
    set record2 = ##class(BUG.Test).%New()
    set record2.Field1 = "Waffles"
    set record2.Field2 = "Syrup"
    set sc = record2.%Save()
    if $$$ISERR(sc) {
        do $System.OBJ.DisplayError(sc)
    } else {
        write !,"Save OK ID: "_record2.%Id()
    }

    ; Should fail on duplicate "unique" value for Field1
    set record3 = ##class(BUG.Test).%New()
    set record3.Field1 = "Bosco"
    set record3.Field2 = "Jones"
    set sc = record3.%Save()
    if $$$ISERR(sc) {
        do $System.OBJ.DisplayError(sc)
    } else {
        write !,"Save OK ID: "_record3.%Id()
    }
}

I get this as the output.

>d ##class(BUG.Test).Test()
 
Save OK ID: 1
Save OK ID: 2
ERROR #5808: Key not unique: BUG.Test:idx1:^BUG.TestI("idx1"," BOSCO")
ERROR #5002: Cache error: <ROLLFAIL>%TRollBack+10^%occTransaction

Because when I execute:

>d $System.OBJ.DisplayError(%objlasterror)
 
ERROR #5002: Cache error: <ROLLFAIL>%TRollBack+10^%occTransaction

Is the "ROLLFAIL" the expected error and I've just never noticed before? Or is this something that has changed in recent times? It seems odd that the "Key Not Unique" isn't the "last error".

Discussion (4)1
Log in or sign up to continue