Bug 107523 - Inconsistent, history-dependent results of referencing missing variables in conditional text
Summary: Inconsistent, history-dependent results of referencing missing variables in c...
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
5.2.6.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Fields
  Show dependency treegraph
 
Reported: 2017-04-30 05:25 UTC by Eric Christenson
Modified: 2018-06-24 19:56 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
10 line demo of issue (12.39 KB, application/vnd.oasis.opendocument.text)
2017-04-30 05:28 UTC, Eric Christenson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Christenson 2017-04-30 05:25:16 UTC
Description:
conditional text, conditional sections, Writer 5.2.6.2, the result of evaluating a conditional text or a condition to hide a section seems to depend on whether the variable was previously set in the document, even if the field that set it has since been erased with the "delete" key.

If I write my conditional text field first, and never set the variable referenced therein, it seems to evaluate TRUE.  If I then set the variable referenced therein, with a field in front of the conditional text, things work as expected.  If I then delete that field, the condition (just the variable) evaluates as FALSE.  The only user-apparent difference between the two states is the history of editing the document.


Steps to Reproduce:
1.new writer document.
2.Insert conditional Text using SecondVar (Conditional Text SecondVar -- SecondVar is Set: SecondVar is Clear).
2. Note: SecondVar evaluates to Set
3.Insert Conditional Text using BoolVar (Condtional Text BoolVar -- BoolVar is Set: BoolVar is Clear).
4. Insert fields/more fields, variables, BoolVar, format Boolean, value TRUE
5. Note: BoolVar evaluates to Set.
6. Erase BoolVar field.
7. BoolVar now evaluates to Clear. 

Actual Results:  
7. BoolVar now evaluates to clear, unlike SecondVar, which evaluates to set.

Expected Results:
BoolVar should have evaluated to Set, or SecondVar should have evaluated to Clear. (or, alternatively, there should be a way within an expression to tell if a variable has been set or not)


Reproducible: Always

User Profile Reset: No

Additional Info:
More generally, LO Writer *should* be consistent in its handling of uninitialized fields when they are tested.  I'd like to see a defined() operator, like in the C pre-processor, to test whether a user variable has been set or not.

I have a much longer document where a more complicated conditional (A OR B OR C) evaluates differently on the first and second consecutive evaluation, two lines apart.


User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0
Comment 1 Eric Christenson 2017-04-30 05:28:21 UTC
Created attachment 132957 [details]
10 line demo of issue

also demos bug 84148.
Comment 2 Eric Christenson 2017-04-30 05:32:34 UTC
seems related to 92662 -- here, a variable has evidently been created with no position in the document.

Use case:  A document template uses conditional sections, and is included in multiple master documents with different variable settings.
Comment 3 Buovjaga 2017-04-30 11:27:59 UTC
(In reply to Eric Christenson from comment #0)
> 5. Note: BoolVar evaluates to Set.

At this point, BoolVar evaluated to Clear for me. It stayed that way after I deleted the BoolVar field. I did the steps from scratch, not using the document.

Is this inconsistent enough to confirm or what the heck is expected?

Arch Linux 64-bit
Version: 5.4.0.0.alpha1+
Build ID: aca48f46895811009ec90665d816ef835f0694be
CPU threads: 8; OS: Linux 4.10; UI render: default; VCL: kde4; 
Locale: fi-FI (fi_FI.UTF-8); Calc: group
Built on 30th April 2017
Comment 4 Regina Henschel 2017-04-30 21:27:46 UTC
(In reply to Eric Christenson from comment #0)
> Description:
> conditional text, conditional sections, Writer 5.2.6.2, the result of
> evaluating a conditional text or a condition to hide a section seems to
> depend on whether the variable was previously set in the document, even if
> the field that set it has since been erased with the "delete" key.

The "delete" key does not erase a variable totally but only the "set" field. After the "set" field is erased, go to Insert > Field > More Fields, tab Variables. You will find the variable still listed there. Select it. Then you can use the read cross on the right side of "Name" "Value" to really delete the variable.
Comment 5 Eric Christenson 2017-04-30 23:46:39 UTC
The *delete* key doesn't actually *delete* a variable when it deletes the field that sets it?????  

Expected: If I set a variable at some point in a field in a document, the value applies from that point forward in the document, and is not available prior to that point.  If the field is erased from the document with the delete key (or any other standard way of removing stuff) then Writer acts as if the variable had *never* been set at that point. 

5.2.6.2 behavior is a recipe for trouble, not to mention bugs like 84148, which I just confirmed. 92662 requests exactly this, variables with no position in the document, but conceptually at the beginning.

The behavior is counter-intuitive--I have to delete something I inserted once in two places.  I have an extra place I have to audit if I want to know all the variables in the document.  While I'm at it, what happens if I want to *change* the value of a variable in the middle of a document?

****
And why do I do these things?.... I am producing a *class* of similar documents and assembling them, if I can, automatically from pieces.  I produce a product with multiple options, and the conception is to "turn the crank" and export a document with exactly the options that are present for any given instance of the product.

******
Comment 6 Jean-Baptiste Faure 2018-06-24 19:56:37 UTC
You are confusing 2 different things: the definition of a variable and the use of this variable.
If deleting a field setting a variable deleted the variable too, it would be impossible to number equations and remove a numbered equation without having to create the numbering variable again.

According comment #4, I close this bug report as NotABug.

Best regards. JBF