Bug 162962 - Scriptforge (python) doesn’t work anymore in LO 24.8.1 in Windows 11
Summary: Scriptforge (python) doesn’t work anymore in LO 24.8.1 in Windows 11
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
24.8.1.2 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:25.2.0 target:24.8.2
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2024-09-14 14:43 UTC by John van Mersbergen
Modified: 2024-09-22 14:39 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments
Libre Office faillure message (28.83 KB, image/png)
2024-09-14 18:02 UTC, John van Mersbergen
Details
the failure-test on LO 24.8.2 (203.67 KB, application/vnd.oasis.opendocument.text)
2024-09-18 09:43 UTC, John van Mersbergen
Details
Scriptforge test LO 24.8.2 (239.11 KB, application/vnd.oasis.opendocument.text)
2024-09-21 10:40 UTC, John van Mersbergen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John van Mersbergen 2024-09-14 14:43:42 UTC
Description:
My python-scripts which uses ScriptForge in Windows 11 don’t work anymore in version 24.8.1. When I start a Calc spreadsheet under this version I get a system error message that states "doc = CreateScriptService(‘Calc’) " is not available.
I think this is a severe problem in version. In the previous versie this problem doesn't exist.

Actual Results:
system error message failure doc = CreateScriptService(‘Calc’)

Expected Results:
I cannot run my python-scripts


Reproducible: Always


User Profile Reset: No

Additional Info:
From an user I received this test witch wihich he reproduced the error:

from scriptforge import CreateScriptService

def testSF_CreateScriptProvider():
    srv = CreateScriptService("Calc")
Comment 1 John van Mersbergen 2024-09-14 18:02:02 UTC
Created attachment 196445 [details]
Libre Office faillure message
Comment 2 Rafael Lima 2024-09-14 21:21:05 UTC
I confirm the issue in:

Version: 24.8.1.2 (X86_64) / LibreOffice Community
Build ID: 87fa9aec1a63e70835390b81c40bb8993f1d4ff6
CPU threads: 4; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded

Also in LO 25.2 master built from source on Linux.

The problem does not happen in:

Version: 24.2.5.2 (X86_64) / LibreOffice Community
Build ID: 420(Build:2)
CPU threads: 16; OS: Linux 6.8; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Ubuntu package version: 4:24.2.5-0ubuntu0.24.04.2
Calc: threaded

I tested this simply using Apso Python Shell and typing the following:

from scriptforge import CreateScriptService
doc = CreateScriptService("Calc")

Fails in 24.8, but works in 24.2.

@JPL any idea what may be happening?
Comment 3 Jean-Pierre Ledure 2024-09-15 16:57:02 UTC
The issue exists as soon as the LO version is >= 24.8 whatever the operating system.

I run tests in 24.2 and 24.8 with identical ScriptForge sources. The result is that everything is OK in 24.2 and nothing is OK in 24.8. ScriptForge is broken both in Python and Basic. Many other user scripts are broken as well, I presume.

The issue is in fact that the error "Variable not defined" is raised on a Basic 
   End With
statement, which is VERY strange.

I reproduce the issue with a already much simpler piece of code:
Sub Main
Dim a, b, c, d
	GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
	GlobalScope.BasicLibraries.loadLibrary("XrayTool")
	SF_Utils._InitializeRoot(True)
	a = SF_Utils._GetUNOService("BrowseNodeFactory")
	xray a
End Sub

My observations so far:
- it seems related with the presence of embedded With statements, what SF uses abundantly ...
- The With statement has been revisited between 24.2 and 24.8: it is now possible to put a breakpoint on a With or a End With statement (also strange IMO).

I will continue to search for a minimal code that causes the error to document it more precisely, if possible.

I do not assign the bug to myself, as I do not consider that the ScriptForge piece of code is involved in the first place.

Thanks for reporting the bug.
Comment 4 Rafael Lima 2024-09-15 17:16:12 UTC
Thanks JPL for the analysis.

So this may be related to bug 162935.

@Mike, any idea if this ticket is related? I tested today with your fix for bug 162935 applied, but still I'm getting the same error reported by JPL.

Running this code...

Sub Main
    Dim a, b, c, d
    GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
    SF_Utils._InitializeRoot(True)
    a = SF_Utils._GetUNOService("BrowseNodeFactory")
End Sub

... will causa an error at the end of the With statement.

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 735ca7328e2303ff39523f75b59547bd356e33a0
CPU threads: 16; OS: Linux 6.8; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Calc: CL threaded
Comment 5 Mike Kaganski 2024-09-15 17:51:04 UTC
(In reply to Rafael Lima from comment #4)
> @Mike, any idea if this ticket is related?

It is related to bug 132064 fix, so it is similar to bug 162935, as both are regressions from that.

Thank you both for the analysis!
I don't know if there is a unit test suite for SF; if there is, I would appreciate, if you create a unit test for this, after the fix lands. Thanks again!
Comment 6 Mike Kaganski 2024-09-15 18:05:56 UTC
https://gerrit.libreoffice.org/c/core/+/173417
Comment 7 HarrySpier 2024-09-15 19:32:40 UTC Comment hidden (off-topic)
Comment 8 Commit Notification 2024-09-16 10:59:56 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/40d0e6f4c4ca31f6525b4c84924f2330a166182c

tdf#162962: always create a local "Nothing" for the "WITH" variable

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 9 Rafael Lima 2024-09-16 14:53:23 UTC
(In reply to Mike Kaganski from comment #5)
> I don't know if there is a unit test suite for SF; if there is, I would
> appreciate, if you create a unit test for this, after the fix lands. Thanks
> again!

No... we still do not have Unit tests in the core repo.

This is something that we need to start working on.
Comment 10 Mike Kaganski 2024-09-17 04:48:09 UTC Comment hidden (off-topic)
Comment 11 Commit Notification 2024-09-17 14:16:48 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/af065575843273f242209d30f3cfda33d40974f0

tdf#162962: always create a local "Nothing" for the "WITH" variable

It will be available in 24.8.2.

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 12 John van Mersbergen 2024-09-18 09:43:27 UTC
Created attachment 196520 [details]
the failure-test on LO 24.8.2

My Scriptforge tests failed again on LO 24.8.2
Comment 13 Mike Kaganski 2024-09-18 09:49:04 UTC
(In reply to John van Mersbergen from comment #12)
> My Scriptforge tests failed again on LO 24.8.2

... which full version (from the About dialog) you didn't mention, but based on the ODT metadata, that was 10f5e3d255c094bb34155f6354b93e93289e43a0, which was from 2024-09-16, while this bug was only fixed on 2024-09-17, and the commit notification told to use the daily available in the next 24-48 hours.
Comment 14 John van Mersbergen 2024-09-21 10:40:49 UTC
Created attachment 196586 [details]
Scriptforge test LO 24.8.2

Both my tests succeeded, so this bug seems to be fixed.