Bug 1274696

Summary: An expired event deletion fails
Product: [Retired] JBoss BRMS Platform 6 Reporter: Marek Winkler <mwinkler>
Component: BREAssignee: Mario Fusco <mfusco>
Status: CLOSED EOL QA Contact: Marek Winkler <mwinkler>
Severity: high Docs Contact:
Priority: high    
Version: 6.2.0CC: kverlaen
Target Milestone: ER5   
Target Release: 6.2.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-27 19:05:34 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Marek Winkler 2015-10-23 12:00:27 UTC
Description of problem:

Having the following rule:

declare Event
    @role( event )
    id : long
end

declare Absence
    id : long
end

rule "detect absence"
when
	$event : Event(  )
    not (
        Event(
            this != $event,
            id == $event.id,
            this after[0ms, 3100ms] $event
        )
    )
    not (Absence( 
            id == $event.id
    	)
    )
then
    delete($event)
    insert(new Absence($event.id))
end

and the following sequence of commands:

  session.insert(eventFactType.newInstance());
  session.fireAllRules();
  clock.advanceTime(3300, TimeUnit.MILLISECONDS);
  session.fireAllRules();

The evaluation of rule's consequence fails with the following exception:

  org.kie.api.runtime.rule.ConsequenceException: Exception executing consequence for rule "detect absence" in org.jboss.qa.brms.bre.regression: [Error: delete($event): Update error: handle not found for object: Event( id=0 ). Is it in the working memory?]
[Near : {... delete($event); ....}]
             ^
[Line: 1, Column: 1]
	at org.drools.core.base.DefaultKnowledgeHelper.getFactHandle(DefaultKnowledgeHelper.java:383)
...

The problem seems to be that the event expires before the rule consequence is executed and the delete() command fails. This indeed makes sense; however, since this test-case passed with BRMS 6.1.x, I would like to make sure that this change in behavior is intended and not a bug. Could you please confirm?

If this is intended, is there a way how to delete a fact "safely", i.e. that would delete the fact only if it actually is present in WM at the time when the delete is called?

An interesting fact (for me) is that when you remove the first session.fireAllRules() call, the exception does not occur.

Version-Release number of selected component (if applicable):
BRMS 6.2.0 ER4

How reproducible:
always

Steps to Reproduce:
I will attach a PR with reproducer, if needed.

Actual results:
Fact deletion fails because the event has already expired.

Expected results:
Not sure if this is the expected behavior or not.

Comment 1 Marek Winkler 2015-10-23 12:27:39 UTC
PR with reproducer: https://github.com/droolsjbpm/drools/pull/523

Comment 3 Mario Fusco 2015-10-27 17:45:03 UTC
Fixed by https://github.com/droolsjbpm/drools/commit/3e455f3cf

Comment 4 Marek Winkler 2015-11-05 12:26:29 UTC
Verified in BRMS 6.2.0 ER5.