Bug 161616 - Goal seek macro corrupts the data in Calc cell
Summary: Goal seek macro corrupts the data in Calc cell
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.4 all versions
Hardware: All All
: medium normal
Assignee: Xisco Faulí
URL:
Whiteboard: target:25.2.0 target:24.8.0.0.beta2
Keywords:
Depends on:
Blocks: GoalSeek
  Show dependency treegraph
 
Reported: 2024-06-17 13:40 UTC by Xisco Faulí
Modified: 2024-06-17 22:08 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Xisco Faulí 2024-06-17 13:40:11 UTC
This is a follow-up of bug 161338

Steps to reproduce:
1. Open attachment 194447 [details] from bug 161338
2. Execute the following code

Sub TestGoalSeek
  oSheet = ThisComponent.Sheets(0)
  oTargetCell = oSheet.getCellRangeByName("D1")
  oVariableCell = oSheet.getCellRangeByName("C1")
  oResult = Thiscomponent.seekGoal(oTargetCell.CellAddress, oVariableCell.CellAddress, "100")
  MsgBox oResult.Result
End Sub

3. Go back to the sheet

-> C1 and D1 become #N/A
Comment 1 Xisco Faulí 2024-06-17 13:41:10 UTC
Reproduced in

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: a298ba36047e17cf6a0f6b3d17ae40aed282f47b
CPU threads: 8; OS: Linux 6.1; UI render: default; VCL: gtk3
Locale: es-ES (es_ES.UTF-8); UI: en-US
Calc: threaded

and

Version: 7.3.0.0.alpha1+ / LibreOffice Community
Build ID: 229123ccc6f90ebf66b3e659bebbd53f8a9bdd3a
CPU threads: 8; OS: Linux 6.1; UI render: default; VCL: gtk3
Locale: fr-FR (es_ES.UTF-8); UI: en-US
Calc: threaded
Comment 2 Xisco Faulí 2024-06-17 13:42:05 UTC
@Rafael, @Mike, I thought you might be interested in this issue since you fixed bug 161338
Comment 3 Mike Kaganski 2024-06-17 13:47:01 UTC
We explicitly kept the behavior of the XGoalSeek's seekGoal. Rafael even mentioned that explicitly in the commit message [1]:

> Note that the solver definition in ScDocument::Solver forcefully inserts N/A
> when the solver fails, which seems to be usefull when creating scripts that use
> the Goal Seek.

I don't know why is that done. I also kept that, changing the implementation that actually writes that #N/A. Since this could be an API break, I would like to know why was that done initially.

[1] https://git.libreoffice.org/core/+/d05f1ec2e20eb86ceb99e9ff5d4efb9ff9356dbb
Comment 4 Xisco Faulí 2024-06-17 13:57:38 UTC
I see, at least it would be nice to be able to undo it, so the values are restored
Comment 5 Mike Kaganski 2024-06-17 15:08:06 UTC
On the second thought - it is valid. Let's remove that oddity, and see who shouts :-)
Comment 6 Mike Kaganski 2024-06-17 15:08:59 UTC
(I have no spare cycles at the moment, please take it if you like)
Comment 7 Rafael Lima 2024-06-17 16:12:04 UTC
(In reply to Mike Kaganski from comment #5)
> On the second thought - it is valid. Let's remove that oddity, and see who
> shouts :-)

You mean remove the "N/A" even on macros?

TBH I think this may have been an implementation error back when Goal Seek was introduced. I'm in favor of removing this oddity as well.
Comment 8 Mike Kaganski 2024-06-17 16:27:48 UTC
(In reply to Rafael Lima from comment #7)
> You mean remove the "N/A" even on macros?

Yes :-)
Somehow, Xisco forgot to assign this to himself: https://gerrit.libreoffice.org/c/core/+/169035
Comment 9 Xisco Faulí 2024-06-17 18:32:30 UTC
(In reply to Mike Kaganski from comment #8)
> (In reply to Rafael Lima from comment #7)
> > You mean remove the "N/A" even on macros?
> 
> Yes :-)
> Somehow, Xisco forgot to assign this to himself:
> https://gerrit.libreoffice.org/c/core/+/169035

yep, sorry for that!
Comment 10 Commit Notification 2024-06-17 18:32:32 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/98c74adf2e1945599f693c26d72141553bd7955b

tdf#161616: do not set error when XGoalSeek fails

It will be available in 25.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2024-06-17 22:08:09 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/302029b9cd41ac31a5be3787147a86a4f9e507de

tdf#161616: do not set error when XGoalSeek fails

It will be available in 24.8.0.0.beta2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.