[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [HTCondor-users] Comparing evaluation result with "classad.Value.Error" throws error



Hi Brian,

 

Now I understand why boolean comparison or isinstance() is not working, even though âclassad.ExprTree('1/0').eval()â returns âclassad.classad.Value.Errorâ

Hours of debugging finally come to an end ð  I tested and your suggestion works perfect.

 

Thanks a lot,

Ceyhun

 

From: HTCondor-users <htcondor-users-bounces@xxxxxxxxxxx> on behalf of "Bockelman, Brian" <BBockelman@xxxxxxxxxxxxx>
Reply to: HTCondor-Users Mail List <htcondor-users@xxxxxxxxxxx>
Date: Saturday, 8 May 2021 at 21:58
To: HTCondor-Users Mail List <htcondor-users@xxxxxxxxxxx>
Subject: Re: [HTCondor-users] Comparing evaluation result with "classad.Value.Error" throws error

 

Hi Ceyhun,

 

Indeed, this is a subtle one!  Excellent question.

 

Short answer: You want "value is classad.Value.Error".

 

Long answer:

 

The _expression_ "value == classad.Value.Error" results in a classad.ExprTree object which has the representation "error == error".  The "if" clause coerces the _expression_ to a boolean.  Thus, "error == error" is evaluated to the classad Value object "error" (as comparing anything to an error is still an error; "1 == error" evaluates to an error as well!)

 

Now, what's the boolean value of "error"?  Before the 8.9 series, boost converted error to the integer value "2" (sadly, this is the C++ enumerated value) and hence "error" returned "true" because bool(2) is True in python.  This was tricky because an _expression_ like "1 == classad.Value.Error" would also return true as well as "classad.Value.Undefined == classad.Value.Error".  Whoops!

 

In 8.9, converting an "error" object to a boolean raises an exception to avoid this mistake.

 

Instead, "value is classad.Value.Error" returns whether value and classad.Value.Error are the same object instead of trying to evaluate a ClassAd _expression_.  Hence, your code can be simplified to:

 

value = ad.eval(key)

if value is classad.Value.Error:

   ...

 

(It's unfortunate but these are the sort of tricky edge cases that appear when trying to model the subtly-different boolean logic of ClassAds in a pythonic manner.)

 

Brian



On May 8, 2021, at 2:27 PM, Ceyhun Uzunoglu <ceyhun.uzunoglu@xxxxxxx> wrote:

 

Dear htcondor community,

 

Iâm upgrading my codebase to htcondor v9.0.0 from v8.7.9.

As it is mentioned in this comment[1], comparison of âclassad.Value.Errorâ throws âclassad.ClassAdEvaluationError: Unable to evaluate _expression_.â exception.

What do you suggest to use instead of line-3. Iâm trying to check evaluation result is not a classad.Value.Error.

 

1. value = ad.eval(key)

2. if isinstance(value, classad.Value):
3.    if value == classad.Value.Error:

 

Kind regards,

Ceyhun Uzunoglu

 

 

 

_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to 
htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/